fix: 分区包按 Id 查询避免大 JSON 参与 ORDER BY filesort
All checks were successful
Build and Deploy / deploy (push) Successful in 57s
All checks were successful
Build and Deploy / deploy (push) Successful in 57s
bb8c0a9 后查价 hydrate 会 SELECT Content 并 ORDER BY,大分区包打满 sort_buffer;改为先取 Id 再按主键加载。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a9f8373ec3
commit
1704c9f1e2
@ -80,12 +80,15 @@ public class KpiAreaRepository : OmsSqlSugarRepository<KpiArea>, IKpiAreaReposit
|
|||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var db = await GetDbContextAsync(cancellationToken);
|
var db = await GetDbContextAsync(cancellationToken);
|
||||||
var rows = await db.Queryable<KpiAreaPublishRecord>()
|
// Content 为大 JSON:禁止 SELECT * + ORDER BY(filesort 打满 sort_buffer)
|
||||||
|
var ids = await db.Queryable<KpiAreaPublishRecord>()
|
||||||
.Where(x => x.AreaId == areaId && x.ContentHash == contentHash)
|
.Where(x => x.AreaId == areaId && x.ContentHash == contentHash)
|
||||||
.OrderBy(x => x.Id, OrderByType.Desc)
|
.OrderBy(x => x.Id, OrderByType.Desc)
|
||||||
|
.Select(x => x.Id)
|
||||||
.Take(1)
|
.Take(1)
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
return rows.FirstOrDefault();
|
var id = ids.FirstOrDefault();
|
||||||
|
return id <= 0 ? null : await GetPublishByIdAsync(id, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<KpiAreaPublishRecord?> GetPublishByAreaIdAndVersionAsync(
|
public async Task<KpiAreaPublishRecord?> GetPublishByAreaIdAndVersionAsync(
|
||||||
@ -99,12 +102,15 @@ public class KpiAreaRepository : OmsSqlSugarRepository<KpiArea>, IKpiAreaReposit
|
|||||||
}
|
}
|
||||||
|
|
||||||
var db = await GetDbContextAsync(cancellationToken);
|
var db = await GetDbContextAsync(cancellationToken);
|
||||||
var rows = await db.Queryable<KpiAreaPublishRecord>()
|
// 查价 hydrate 分区包会走这里;先只排 Id,再按主键取 Content
|
||||||
|
var ids = await db.Queryable<KpiAreaPublishRecord>()
|
||||||
.Where(x => x.AreaId == areaId && x.Version == version)
|
.Where(x => x.AreaId == areaId && x.Version == version)
|
||||||
.OrderBy(x => x.Id, OrderByType.Desc)
|
.OrderBy(x => x.Id, OrderByType.Desc)
|
||||||
|
.Select(x => x.Id)
|
||||||
.Take(1)
|
.Take(1)
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
return rows.FirstOrDefault();
|
var id = ids.FirstOrDefault();
|
||||||
|
return id <= 0 ? null : await GetPublishByIdAsync(id, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<KpiAreaPublishRecord>> GetPublishHeadersByAreaIdAsync(
|
public async Task<List<KpiAreaPublishRecord>> GetPublishHeadersByAreaIdAsync(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user