如何解决查询耗时 20 秒以上的 blob 图像
- 图像表 - 298 行
- 页表 - 91 行
- 站点表 = 10 行
创建一个视图,其中包含 PageTypeID = 1 的页面
视图示例:
--------------------------------------------------------------------------------
| Id | RecordedDT | RecordedUET | Image | SiteID
--------------------------------------------------------------------------------
| 22 | 2021-02-03 11:38:37.843| 1612352317 | blobimage | 2
| 23 | 2021-02-03 11:38:38.310| 1612352318 | blobimage | 2
| 24 | 2021-02-03 11:38:38.543| 1612352318 | blobimage | 2
| 25 | 2021-02-03 12:07:18.263| 1612354038 | blobimage | 2
| 26 | 2021-02-03 12:07:18.740| 1612354038 | blobimage | 2
--------------------------------------------------------------------------------
视图在 2 秒内返回所有 108 行(这很好) 问题在于页面加载时间超过 20 秒的代码
private void GetCarouselImages()
{
var imgs = db.CarouselImages
.ToList();
rCarousel.DataSource = imgs;
rCarousel.DataBind();
}
<div id="myCarousel" class="carousel slide" data-ride="carousel" >
<div class="carousel-inner" role="listbox">
<asp:Repeater ID="rCarousel" runat="server">
<ItemTemplate>
<div class="carousel-item <%#GetActiveClass(Container.ItemIndex) %>">
<div class="d-flex justify-content-center w-100 h-100">
<img class="img-responsive" alt="<%#Eval("RecordedUET")%>" src="<%# GetImage(Eval("Image")) %>" />
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
我知道图像必须使用 eval 中的 GetImage 类,但我只使用 db.CarouselImages 为查询计时,这就是占用大部分时间的内容。
GetImage 类(如果需要):
public string GetImage(object img)
{
return "data:image/jpg;base64," + Convert.ToBase64String((byte[])img);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。