当前位置:网站首页>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
边栏推荐
- Docker's latest super detailed tutorial - docker creates, runs, and mounts MySQL
- 性能更佳、使用更简单的懒加载IntersectionObserverEntry(观察者)
- What is the function of fileappender in logback?
- Amazon cloud assistant applet is coming!
- [100 cases of unity practice] the single choice multiple choice judgment questions of unity universal question answering system are all common
- Getting started with JDBC
- Job 7.28 file IO and standard IO
- Meeting notice of OA project (Query & whether to attend the meeting & feedback details)
- 【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
- @RequestMapping 用法详解
猜你喜欢

Use of gcc/g++

分析25个主要DeFi协议的路线图 预见DeFi未来的七大趋势

Getting started with JDBC

电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?

Job 7.28 file IO and standard IO

A long article --- in-depth understanding of synchronized

2-unified return class dto object

I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test

2-统一返回类DTO对象

0 9 布隆过滤器(Bloom Filter)
随机推荐
能在SQL 语句中 指定 内存参数吗?
Scala higher order (IX): pattern matching in Scala
Gin abort cannot prevent subsequent code problems
CDC source can quit after reading MySQL snapshot split
写点dp
I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test
【MYSQL】-【子查询】
QT basic day 2 (2) QT basic components: button class, layout class, output class, input class, container and other individual examples
[daily question in summer] Luogu p6408 [coci2008-2009 3] pet
利用C语言巧妙实现棋类游戏——三子棋
UPC 小C的王者峡谷
STM32 operation w25q256 w25q16 SPI flash
Getting started with JDBC
7-2 计算正五边形的面积和周长 (25分)
QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
Prometheus与Grafana
CFdiv1+2-Bash and a Tough Math Puzzle-(线段树单点区间维护gcd+总结)
Description of rollingfileappender attribute in logback
Does Flink support sqlserver databases? Get the changes of SQLSERVER database
How can electronic component trading enterprises solve warehouse management problems with ERP system?