Skip to content

Commit 88a20cb

Browse files
Minor query cleanup
1 parent a6b04a9 commit 88a20cb

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ public IEnumerable<IDictionaryItem> GetDictionaryItemDescendants(Guid? parentId)
261261
Func<Guid[], IEnumerable<IEnumerable<IDictionaryItem>>> getItemsFromParents = guids =>
262262
{
263263
return guids.InGroupsOf(Constants.Sql.MaxParameterCount)
264-
.Select(@group =>
264+
.Select(group =>
265265
{
266266
var sqlClause = GetBaseQuery(false)
267267
.Where<DictionaryDto>(x => x.Parent != null)
268-
.Where($"{SqlSyntax.GetQuotedColumnName("parent")} IN (@parentIds)", new { parentIds = @group });
268+
.WhereIn<DictionaryDto>(x => x.Parent, group);
269269

270270
var translator = new SqlTranslator<IDictionaryItem>(sqlClause, Query<IDictionaryItem>());
271271
var sql = translator.Translate();

src/Umbraco.Core/Persistence/Repositories/Implement/MemberRepository.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,13 @@ public IEnumerable<IMember> FindMembersInRole(string roleName, string usernameTo
431431
var matchedMembers = Get(query).ToArray();
432432

433433
var membersInGroup = new List<IMember>();
434+
434435
//then we need to filter the matched members that are in the role
435-
//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
436-
var inGroups = matchedMembers.InGroupsOf(1000);
437-
foreach (var batch in inGroups)
436+
foreach (var group in matchedMembers.Select(x => x.Id).InGroupsOf(Constants.Sql.MaxParameterCount))
438437
{
439-
var memberIdBatch = batch.Select(x => x.Id);
440-
441438
var sql = Sql().SelectAll().From<Member2MemberGroupDto>()
442439
.Where<Member2MemberGroupDto>(dto => dto.MemberGroup == memberGroup.Id)
443-
.WhereIn<Member2MemberGroupDto>(dto => dto.Member, memberIdBatch);
440+
.WhereIn<Member2MemberGroupDto>(dto => dto.Member, group);
444441

445442
var memberIdsInGroup = Database.Fetch<Member2MemberGroupDto>(sql)
446443
.Select(x => x.Member).ToArray();

src/Umbraco.Core/Persistence/Repositories/Implement/RepositoryBaseOfTIdTEntity.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,16 @@ public IEnumerable<TEntity> GetMany(params TId[] ids)
188188
// the additional overhead of fetching them in groups is minimal compared to the lookup time of each group
189189
if (ids.Length <= Constants.Sql.MaxParameterCount)
190190
{
191+
// the additional overhead of fetching them in groups is minimal compared to the lookup time of each group
191192
return CachePolicy.GetAll(ids, PerformGetAll);
192193
}
193194

194195
var entities = new List<TEntity>();
195-
foreach (var groupOfIds in ids.InGroupsOf(Constants.Sql.MaxParameterCount))
196+
foreach (var group in ids.InGroupsOf(Constants.Sql.MaxParameterCount))
196197
{
197-
entities.AddRange(CachePolicy.GetAll(groupOfIds.ToArray(), PerformGetAll));
198+
entities.AddRange(CachePolicy.GetAll(group.ToArray(), PerformGetAll));
198199
}
200+
199201
return entities;
200202
}
201203

0 commit comments

Comments
 (0)