当前位置:网站首页>EF core reading text type is slow_ EF core is slow to read large string fields
EF core reading text type is slow_ EF core is slow to read large string fields
2022-07-29 07:32:00 【Tianma 3798】
One 、ef core Read text Type slow _ef core Reading large string fields is slow
analysis :
When the server configuration is low ,text The rich text string is larger than 100kb When , Use ef Reading data is significantly slower .
Two major features of slowing down :
1.text Type rich text field content is too long ,100kb above
2. When reading, it is also associated with the data of other tables .
These two characteristics , Lead to ef core Slow reading of data , Slow obviously .
Solution :
Business plan :
Suggest text Do not store too large characters in the field ; When the client edits rich text , Remove the style after copying and pasting , Rearrange .
Business plan is preferred , If the field needs to be large , Consider the following technical proposal .
Technical solution :
1. List read content To filter out text Field of , Do not read large text from data
2. Read details , Associate table data with text The fields of are queried separately or , Split into 2 Interface .
Two 、ef core Large text field list reading optimization
Before optimization :
var list = query.Include(q => q.Sch_Label).Include(q => q.Sch_Month).Skip(skip)
.Take(10)
.ToList()
.Select(q => new
{
q.ID,
q.Name,
q.Logo,
q.ViewCount,
q.CreateTime,
AreaShow = q.GetAreaShow(),
MonthShow = q.GetMonthShow(),
LabelList = q.Sch_Label
}).ToList();After the optimization :
var list = query
.Include(q => q.Sch_Label)
.Include(q => q.Sch_Month).Skip(skip)
.Select(q => new School() {
ID = q.ID,
Name = q.Name,
ViewCount = q.ViewCount,
CreateTime = q.CreateTime,
Logo = q.Logo,
Sch_Month = q.Sch_Month,
Sch_Label = q.Sch_Label
})
.Take(10)
.ToList()
.Select(q => new
{
q.ID,
q.Name,
q.Logo,
q.ViewCount,
q.CreateTime,
AreaShow = q.GetAreaShow(),
MonthShow = q.GetMonthShow(),
LabelList = q.Sch_Label
}).ToList();The performance improvement is quite obvious .
3、 ... and 、ef core Large text field detail reading optimization
Association table and text Big text fields , Separate access ; Significantly improved performance .
Before optimization :
// For more details
public IActionResult GetDetail(int id)
{
var model = _school.GetQueryable().Where(q => q.ID == id)
.Include(q => q.Sch_Image)
.Include(q => q.Sch_Label)
.Include(q => q.Sch_Month)
.FirstOrDefault();
JObject obj = JObject.FromObject(model, MvcContext.GetJsonSerializer());
// School Video
VideoOperate _video = new VideoOperate();
var videoList = _video.GetBySchool(id, 8).Select(q => new
{
q.ID,
q.Title,
q.ImgUrl,
q.ViewCount
});
obj.Add("videoList", JArray.FromObject(videoList, MvcContext.GetJsonSerializer()));
// Traffic ++
model.ViewCount++;
_school.Modify(model);
return Json(obj);
}After the optimization :
// For more details
public IActionResult GetDetail(int id)
{
var model = _school.GetQueryable().Where(q => q.ID == id)
//.Include(q => q.Sch_Image)
//.Include(q => q.Sch_Label)
//.Include(q => q.Sch_Month)
.FirstOrDefault();
//JObject obj = JObject.FromObject(model.Result, MvcContext.GetJsonSerializer());
// School Video
//VideoOperate _video = new VideoOperate();
//var videoList = _video.GetBySchool(id, 8).Select(q => new
//{
// q.ID,
// q.Title,
// q.ImgUrl,
// q.ViewCount
//});
//obj.Add("videoList", JArray.FromObject(videoList, MvcContext.GetJsonSerializer()));
// Traffic ++
model.ViewCount++;
_school.Modify(model);
//return Json(obj);
return Json(model);
}
// Get related table data
public IActionResult GetDetailMore(int id)
{
VideoOperate _video = new VideoOperate();
Sch_ImageOperate _img = new Sch_ImageOperate();
// School pictures
var Sch_Image = _img.GetQueryable().Where(q => q.SchID == id).OrderByDescending(q => q.Sort).ToList();
// School labels
var Sch_Label = _img.Context.Sch_Label.Where(q => q.SchID == id).ToList();
// School month
var Sch_Month = _img.Context.Sch_Month.Where(q => q.SchID == id).ToList();
// School Video
var videoList = _video.GetBySchool(id, 8).Select(q => new
{
q.ID,
q.Title,
q.ImgUrl,
q.ViewCount
});
return Json(new
{
Sch_Image,
Sch_Label,
Sch_Month,
videoList
});
}Other related : What a big pit : EF Core Reading large string fields asynchronously is slower than synchronizing 100 Many times | Easy to learn
more :
EF Core Write data in batch and use it for sorting ( Two )Z.EntityFramework.Extensions.EFCore
EF Core Write data in batch and use it for sorting _EF Core Bulk insert data ( One )
EFCore Association table query _ Use multiple tables to organize
边栏推荐
- 【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK
- Scala 高阶(十):Scala中的异常处理
- [OpenGL] use of shaders
- 关于大龄读博的几点回答?
- 【暑期每日一题】洛谷 P4414 [COCI2006-2007#2] ABC
- Android面试题 | 怎么写一个又好又快的日志库?
- 性能更佳、使用更简单的懒加载IntersectionObserverEntry(观察者)
- leetcode力扣经典问题——4.寻找两个正序数组的中位数
- RoBERTa:A Robustly Optimized BERT Pretraining Approach
- 7-2 calculate the area and perimeter of a regular pentagon (25 points)
猜你喜欢
![[MySQL] - [subquery]](/img/81/0880f798f0f41724fd485ae82d142d.png)
[MySQL] - [subquery]

梳理市面上的2大NFT定价范式和4种解决方案

QT topic: basic components (button class, layout class, output class, input class, container class)
Scala 高阶(九):Scala中的模式匹配

QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)

Docker最新超详细教程——Docker创建运行MySQL并挂载

Spingboot integrates the quartz framework to realize dynamic scheduled tasks (support real-time addition, deletion, modification and query tasks)

亚马逊云助手小程序来啦!
![【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK](/img/bf/c0e03f1bf477730f0b3661b3256d1d.png)
【暑期每日一题】洛谷 P6461 [COCI2006-2007#5] TRIK

Prometheus与Grafana
随机推荐
09 bloom filter
3-全局异常处理
【WPF】通过动态/静态资源实现语言切换
[summer daily question] Luogu p4414 [coci2006-2007 2] ABC
stm32 操作W25Q256 W25Q16 spi flash
logback filter过滤器简介说明
mysql 单表最多能存多少数据?
[100 cases of unity practice] the single choice multiple choice judgment questions of unity universal question answering system are all common
jdbc入门
我想问一下,我flink作业是以upsert-kafka的方式写入数据的,但是我在mysql里面去更
强连通分量
[OpenGL] use of shaders
Does Flink support sqlserver databases? Get the changes of SQLSERVER database
利用C语言巧妙实现棋类游戏——三子棋
gin abort不能阻止后续代码的问题
【Unity实战100例】Unity万能答题系统之单选多选判断题全部通用
请问flink支持sqlServer数据库么?获取sqlServer数据库的变化
状态机dp三维
Gin abort cannot prevent subsequent code problems
@Detailed explanation of requestmapping usage