Minor query cleanup

This commit is contained in:
Ronald Barendse
2021-10-13 13:46:51 +02:00
parent a6b04a941c
commit 88a20cb13c
3 changed files with 10 additions and 11 deletions

View File

@@ -261,11 +261,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
Func<Guid[], IEnumerable<IEnumerable<IDictionaryItem>>> getItemsFromParents = guids =>
{
return guids.InGroupsOf(Constants.Sql.MaxParameterCount)
.Select(@group =>
.Select(group =>
{
var sqlClause = GetBaseQuery(false)
.Where<DictionaryDto>(x => x.Parent != null)
.Where($"{SqlSyntax.GetQuotedColumnName("parent")} IN (@parentIds)", new { parentIds = @group });
.WhereIn<DictionaryDto>(x => x.Parent, group);
var translator = new SqlTranslator<IDictionaryItem>(sqlClause, Query<IDictionaryItem>());
var sql = translator.Translate();

View File

@@ -431,16 +431,13 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
var matchedMembers = Get(query).ToArray();
var membersInGroup = new List<IMember>();
//then we need to filter the matched members that are in the role
//since the max sql params are 2100 on sql server, we'll reduce that to be safe for potentially other servers and run the queries in batches
var inGroups = matchedMembers.InGroupsOf(1000);
foreach (var batch in inGroups)
{
var memberIdBatch = batch.Select(x => x.Id);
//then we need to filter the matched members that are in the role
foreach (var group in matchedMembers.Select(x => x.Id).InGroupsOf(Constants.Sql.MaxParameterCount))
{
var sql = Sql().SelectAll().From<Member2MemberGroupDto>()
.Where<Member2MemberGroupDto>(dto => dto.MemberGroup == memberGroup.Id)
.WhereIn<Member2MemberGroupDto>(dto => dto.Member, memberIdBatch);
.WhereIn<Member2MemberGroupDto>(dto => dto.Member, group);
var memberIdsInGroup = Database.Fetch<Member2MemberGroupDto>(sql)
.Select(x => x.Member).ToArray();

View File

@@ -188,14 +188,16 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
// the additional overhead of fetching them in groups is minimal compared to the lookup time of each group
if (ids.Length <= Constants.Sql.MaxParameterCount)
{
// the additional overhead of fetching them in groups is minimal compared to the lookup time of each group
return CachePolicy.GetAll(ids, PerformGetAll);
}
var entities = new List<TEntity>();
foreach (var groupOfIds in ids.InGroupsOf(Constants.Sql.MaxParameterCount))
foreach (var group in ids.InGroupsOf(Constants.Sql.MaxParameterCount))
{
entities.AddRange(CachePolicy.GetAll(groupOfIds.ToArray(), PerformGetAll));
entities.AddRange(CachePolicy.GetAll(group.ToArray(), PerformGetAll));
}
return entities;
}