当前位置:网站首页>ef core 读取text类型慢_ef core读取大字符串字段慢
ef core 读取text类型慢_ef core读取大字符串字段慢
2022-07-29 07:17:00 【天马3798】
一、ef core 读取text类型慢_ef core读取大字符串字段慢
分析:
当服务器配置低,text富文本字符串比较大超过100kb的时候,使用ef读取数据明显变慢。
变慢的两大使用特点:
1.text 类型富文本字段内容太长,100kb以上
2.读取时候还关联了其他表的数据。
此两种特点,导致ef core读取数据慢,慢的明显。
解决方案:
业务方案:
建议text字段不要存入太大的字符;再客户编辑富文本时候,复制粘贴后去掉样式,重新排版。
业务方案优先考虑,如果确实字段需要内容大,再考虑下方技术方案。
技术方案:
1.列表读取内容 过滤掉text的字段,不从数据读取大文本
2.详情读取内容,将关联表数据和text的字段分开查询或者,拆分成2个接口。
二、ef core大文本字段列表读取优化
优化之前:
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();优化之后:
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();性能提升相当明显。
三、ef core大文本字段详情读取优化
关联表和 text大文本字段,分开获取;性能提升明显。
优化之前:
//获取详情
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());
//学校视频
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()));
//流量++
model.ViewCount++;
_school.Modify(model);
return Json(obj);
}优化之后:
//获取详情
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());
//学校视频
//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()));
//流量++
model.ViewCount++;
_school.Modify(model);
//return Json(obj);
return Json(model);
}
//获取关联表资料
public IActionResult GetDetailMore(int id)
{
VideoOperate _video = new VideoOperate();
Sch_ImageOperate _img = new Sch_ImageOperate();
//学校图片
var Sch_Image = _img.GetQueryable().Where(q => q.SchID == id).OrderByDescending(q => q.Sort).ToList();
//学校标签
var Sch_Label = _img.Context.Sch_Label.Where(q => q.SchID == id).ToList();
//学校月份
var Sch_Month = _img.Context.Sch_Month.Where(q => q.SchID == id).ToList();
//学校视频
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
});
}其他相关:好大一个坑: EF Core 异步读取大字符串字段比同步慢100多倍 | 易学教程
更多:
EF Core 批量写入数据使用整理(二)Z.EntityFramework.Extensions.EFCore
EF Core 批量写入数据使用整理_EF Core批量插入数据(一)
EFCore 关联表查询_多表使用整理
边栏推荐
猜你喜欢
Scala higher order (IX): pattern matching in Scala

It's enough for MySQL to have this article (disgusting and crazy typing 37k words, just for Bo Jun's praise!!!)

第7节-程序的编译(预处理操作)+链接

Nodejs installation tutorial

Job 7.28 file IO and standard IO

如何与斯堪尼亚SCANIA建立EDI连接?

使用自定义注解校验list的大小

用户列表 圆形头像并跟随小板块

STM32 operation w25q256 w25q16 SPI flash
![Explanation of suffix automata (SAM) + Luogu p3804 [template] suffix automata (SAM)](/img/8b/f68503e09f218c26e34453b1b7fcd5.png)
Explanation of suffix automata (SAM) + Luogu p3804 [template] suffix automata (SAM)
随机推荐
halcon的安装以及在vs2017中测试,vs2017中dll的配置
[daily question in summer] Luogu p6408 [coci2008-2009 3] pet
Full process flow of CMOS chip manufacturing
Gin routing, parameters, output
Does Flink support sqlserver databases? Get the changes of SQLSERVER database
[MySQL] - [subquery]
第7节-程序的编译(预处理操作)+链接
新生代公链再攻「不可能三角」
jdbc入门
QT基础第二天(2)qt基础部件:按钮类,布局类,输出类,输入类,容器等个别举例
0 9 布隆过滤器(Bloom Filter)
logback filter过滤器简介说明
同步/异步、阻塞/非阻塞 与 IO
7-2 计算正五边形的面积和周长 (25分)
如何与斯堪尼亚SCANIA建立EDI连接?
Female graduate students do "mind mapping" and quarrel with their boyfriend! Netizen: the "king of infighting" in the quarrel
QT专题:基础部件(按钮类,布局类,输出类,输入类,容器类)
CMOS芯片制造全工艺流程
LevelFilter简介说明
JS day 4 process control (if statement and switch statement)