当前位置:网站首页>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
边栏推荐
- CDC source can quit after reading MySQL snapshot split
- 【暑期每日一题】洛谷 P1601 A+B Problem(高精)
- Meeting notice of OA project (Query & whether to attend the meeting & feedback details)
- 1-后台项目搭建
- do end用法的妙处
- 蓝桥杯A组选数异或
- mysql 单表最多能存多少数据?
- I'd like to ask, my flick job writes data in the way of upsert Kafka, but I'm more careful in MySQL
- RoBERTa:A Robustly Optimized BERT Pretraining Approach
- Synchronous / asynchronous, blocking / non blocking and IO
猜你喜欢

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

女研究生做“思维导图”与男友吵架!网友:吵架届的“内卷之王”....

Amazon cloud assistant applet is coming!

What are the answers about older bloggers?

Using C language to skillfully realize the chess game -- Sanzi chess

QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
![[MySQL] - [subquery]](/img/81/0880f798f0f41724fd485ae82d142d.png)
[MySQL] - [subquery]

MySQL uses the client and select methods to view the summary of blob type fields

Getting started with JDBC

Use of gcc/g++
随机推荐
ef core 读取text类型慢_ef core读取大字符串字段慢
2022年深圳杯A题破除“尖叫效应”与“回声室效应”走出“信息茧房”
Halcon installation and testing in vs2017, DLL configuration in vs2017
QT连接两个qslite数据库报错QSqlQuery::exec: database not open
美智光电IPO被终止:年营收9.26亿 何享健为实控人
【暑期每日一题】洛谷 P4414 [COCI2006-2007#2] ABC
Scala higher order (10): exception handling in Scala
我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
jdbc入门
Paper reading (62):pointer networks
Practice of online problem feedback module (XVII): realize the online download function of excel template
多线程购物
PAT甲级 1154 顶点着色
gin abort不能阻止后续代码的问题
女研究生做“思维导图”与男友吵架!网友:吵架届的“内卷之王”....
Does Flink support sqlserver databases? Get the changes of SQLSERVER database
Levelfilter introduction
受欢迎的牛 G
LANDSCAPE
【暑期每日一题】洛谷 P6500 [COCI2010-2011#3] ZBROJ