Skip to content

Commit

Permalink
V8 implementation of #15206
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmania committed Nov 30, 2023
1 parent bb3bfdb commit 668e841
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public IEnumerable<ContentNodeKit> GetAllMediaSources(IScope scope)
// 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.

foreach (var row in GetContentNodeDtos(sql, scope))
foreach (var row in GetMediaNodeDtos(sql, scope))
{
yield return CreateMediaNodeKit(row, serializer);
}
Expand All @@ -319,7 +319,7 @@ public IEnumerable<ContentNodeKit> GetBranchMediaSources(IScope scope, int id)
// 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.

foreach (var row in GetContentNodeDtos(sql, scope))
foreach (var row in GetMediaNodeDtos(sql, scope))
{
yield return CreateMediaNodeKit(row, serializer);
}
Expand All @@ -339,7 +339,7 @@ public IEnumerable<ContentNodeKit> GetTypeMediaSources(IScope scope, IEnumerable
// 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.

foreach (var row in GetContentNodeDtos(sql, scope))
foreach (var row in GetMediaNodeDtos(sql, scope))
{
yield return CreateMediaNodeKit(row, serializer);
}
Expand Down Expand Up @@ -478,5 +478,30 @@ private IEnumerable<ContentSourceDto> GetContentNodeDtos(Sql<ISqlContext> sql, I

return dtos;
}

private IEnumerable<ContentSourceDto> GetMediaNodeDtos(Sql<ISqlContext> sql)
{
// 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 = SqlMediaSourcesCount()
.Append(SqlObjectTypeNotTrashed(SqlContext, Constants.ObjectTypes.Media));

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);
}

return dtos;
}
}
}

0 comments on commit 668e841

Please # to comment.