Skip to content

Commit 0f16dae

Browse files
committed
Merge remote-tracking branch 'origin/v13/dev' into v14/dev
# Conflicts: # src/Umbraco.Infrastructure/Migrations/Upgrade/V_10_7_0/MigrateTagsFromNVarcharToNText.cs # src/Umbraco.Infrastructure/Migrations/Upgrade/V_12_0_0/UseNvarcharInsteadOfNText.cs
2 parents 4f63324 + 2736a51 commit 0f16dae

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,17 @@ public IEnumerable<ContentNodeKit> GetAllContentSources()
221221
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document))
222222
.Append(SqlOrderByLevelIdSortOrder(SqlContext));
223223

224+
// Use a more efficient COUNT query
225+
Sql<ISqlContext>? sqlCountQuery = SqlContentSourcesCount()
226+
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document));
227+
228+
Sql<ISqlContext>? sqlCount =
229+
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
230+
224231
IContentCacheDataSerializer serializer =
225232
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);
226233

227-
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
234+
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, sqlCount);
228235

229236
foreach (ContentSourceDto row in dtos)
230237
{
@@ -239,10 +246,18 @@ public IEnumerable<ContentNodeKit> GetBranchContentSources(int id)
239246
.Append(SqlWhereNodeIdX(SqlContext, id))
240247
.Append(SqlOrderByLevelIdSortOrder(SqlContext));
241248

249+
// Use a more efficient COUNT query
250+
Sql<ISqlContext>? sqlCountQuery = SqlContentSourcesCount(SqlContentSourcesSelectUmbracoNodeJoin)
251+
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document))
252+
.Append(SqlWhereNodeIdX(SqlContext, id));
253+
254+
Sql<ISqlContext>? sqlCount =
255+
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
256+
242257
IContentCacheDataSerializer serializer =
243258
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);
244259

245-
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
260+
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, sqlCount);
246261

247262
foreach (ContentSourceDto row in dtos)
248263
{
@@ -262,10 +277,18 @@ public IEnumerable<ContentNodeKit> GetTypeContentSources(IEnumerable<int>? ids)
262277
.WhereIn<ContentDto>(x => x.ContentTypeId, ids)
263278
.Append(SqlOrderByLevelIdSortOrder(SqlContext));
264279

280+
// Use a more efficient COUNT query
281+
Sql<ISqlContext> sqlCountQuery = SqlContentSourcesCount()
282+
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document))
283+
.WhereIn<ContentDto>(x => x.ContentTypeId, ids);
284+
285+
Sql<ISqlContext>? sqlCount =
286+
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
287+
265288
IContentCacheDataSerializer serializer =
266289
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);
267290

268-
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
291+
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, sqlCount);
269292

270293
foreach (ContentSourceDto row in dtos)
271294
{
@@ -1015,27 +1038,14 @@ private IEnumerable<ContentSourceDto> GetMediaNodeDtos(Sql<ISqlContext> sql)
10151038
return dtos;
10161039
}
10171040

1018-
private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql)
1041+
private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql, Sql<ISqlContext> sqlCount)
10191042
{
10201043
// We need to page here. We don't want to iterate over every single row in one connection cuz this can cause an SQL Timeout.
10211044
// We also want to read with a db reader and not load everything into memory, QueryPaged lets us do that.
10221045
// QueryPaged is very slow on large sites however, so use fetch if UsePagedSqlQuery is disabled.
1023-
IEnumerable<ContentSourceDto> dtos;
1024-
if (_nucacheSettings.Value.UsePagedSqlQuery)
1025-
{
1026-
// Use a more efficient COUNT query
1027-
Sql<ISqlContext>? sqlCountQuery = SqlContentSourcesCount()
1028-
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document));
1029-
1030-
Sql<ISqlContext>? sqlCount =
1031-
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
1032-
1033-
dtos = Database.QueryPaged<ContentSourceDto>(_nucacheSettings.Value.SqlPageSize, sql, sqlCount);
1034-
}
1035-
else
1036-
{
1037-
dtos = Database.Fetch<ContentSourceDto>(sql);
1038-
}
1046+
IEnumerable<ContentSourceDto> dtos = _nucacheSettings.Value.UsePagedSqlQuery ?
1047+
Database.QueryPaged<ContentSourceDto>(_nucacheSettings.Value.SqlPageSize, sql, sqlCount) :
1048+
Database.Fetch<ContentSourceDto>(sql);
10391049

10401050
return dtos;
10411051
}

0 commit comments

Comments
 (0)