Fixing regression bug introduced in #14806 and found during investigation of #16803 - well tested on db with 300k+ nodes (#16837)
Co-authored-by: Wojciech Tengler <wtengler@umbracare.net>
(cherry picked from commit 688790e90a)
This commit is contained in:
committed by
Zeegaan
parent
bb654360bf
commit
2736a513a3
@@ -221,10 +221,17 @@ AND cmsContentNu.nodeId IS NULL
|
||||
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document))
|
||||
.Append(SqlOrderByLevelIdSortOrder(SqlContext));
|
||||
|
||||
// Use a more efficient COUNT query
|
||||
Sql<ISqlContext>? sqlCountQuery = SqlContentSourcesCount()
|
||||
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document));
|
||||
|
||||
Sql<ISqlContext>? sqlCount =
|
||||
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
|
||||
|
||||
IContentCacheDataSerializer serializer =
|
||||
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);
|
||||
|
||||
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
|
||||
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, sqlCount);
|
||||
|
||||
foreach (ContentSourceDto row in dtos)
|
||||
{
|
||||
@@ -239,10 +246,18 @@ AND cmsContentNu.nodeId IS NULL
|
||||
.Append(SqlWhereNodeIdX(SqlContext, id))
|
||||
.Append(SqlOrderByLevelIdSortOrder(SqlContext));
|
||||
|
||||
// Use a more efficient COUNT query
|
||||
Sql<ISqlContext>? sqlCountQuery = SqlContentSourcesCount(SqlContentSourcesSelectUmbracoNodeJoin)
|
||||
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document))
|
||||
.Append(SqlWhereNodeIdX(SqlContext, id));
|
||||
|
||||
Sql<ISqlContext>? sqlCount =
|
||||
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
|
||||
|
||||
IContentCacheDataSerializer serializer =
|
||||
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);
|
||||
|
||||
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
|
||||
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, sqlCount);
|
||||
|
||||
foreach (ContentSourceDto row in dtos)
|
||||
{
|
||||
@@ -262,10 +277,18 @@ AND cmsContentNu.nodeId IS NULL
|
||||
.WhereIn<ContentDto>(x => x.ContentTypeId, ids)
|
||||
.Append(SqlOrderByLevelIdSortOrder(SqlContext));
|
||||
|
||||
// Use a more efficient COUNT query
|
||||
Sql<ISqlContext> sqlCountQuery = SqlContentSourcesCount()
|
||||
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document))
|
||||
.WhereIn<ContentDto>(x => x.ContentTypeId, ids);
|
||||
|
||||
Sql<ISqlContext>? sqlCount =
|
||||
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
|
||||
|
||||
IContentCacheDataSerializer serializer =
|
||||
_contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Document);
|
||||
|
||||
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql);
|
||||
IEnumerable<ContentSourceDto> dtos = GetContentNodeDtos(sql, sqlCount);
|
||||
|
||||
foreach (ContentSourceDto row in dtos)
|
||||
{
|
||||
@@ -1015,27 +1038,14 @@ WHERE cmsContentNu.nodeId IN (
|
||||
return dtos;
|
||||
}
|
||||
|
||||
private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql)
|
||||
private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql, Sql<ISqlContext> sqlCount)
|
||||
{
|
||||
// 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.
|
||||
// We also want to read with a db reader and not load everything into memory, QueryPaged lets us do that.
|
||||
// QueryPaged is very slow on large sites however, so use fetch if UsePagedSqlQuery is disabled.
|
||||
IEnumerable<ContentSourceDto> dtos;
|
||||
if (_nucacheSettings.Value.UsePagedSqlQuery)
|
||||
{
|
||||
// Use a more efficient COUNT query
|
||||
Sql<ISqlContext>? sqlCountQuery = SqlContentSourcesCount()
|
||||
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Document));
|
||||
|
||||
Sql<ISqlContext>? sqlCount =
|
||||
SqlContext.Sql("SELECT COUNT(*) FROM (").Append(sqlCountQuery).Append(") npoco_tbl");
|
||||
|
||||
dtos = Database.QueryPaged<ContentSourceDto>(_nucacheSettings.Value.SqlPageSize, sql, sqlCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
dtos = Database.Fetch<ContentSourceDto>(sql);
|
||||
}
|
||||
IEnumerable<ContentSourceDto> dtos = _nucacheSettings.Value.UsePagedSqlQuery ?
|
||||
Database.QueryPaged<ContentSourceDto>(_nucacheSettings.Value.SqlPageSize, sql, sqlCount) :
|
||||
Database.Fetch<ContentSourceDto>(sql);
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user