Skip to content

Commit 1bc3290

Browse files
Fix bugs in fetching more than 2000 items (permissions and culture variations)
1 parent 88a20cb commit 1bc3290

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,14 +1094,20 @@ private void RenormalizeDocumentEditedFlags(IReadOnlyCollection<int> propertyTyp
10941094
}
10951095
}
10961096

1097-
//lookup all matching rows in umbracoDocumentCultureVariation
1098-
var docCultureVariationsToUpdate = editedLanguageVersions.InGroupsOf(Constants.Sql.MaxParameterCount)
1099-
.SelectMany(_ => Database.Fetch<DocumentCultureVariationDto>(
1100-
Sql().Select<DocumentCultureVariationDto>().From<DocumentCultureVariationDto>()
1101-
.WhereIn<DocumentCultureVariationDto>(x => x.LanguageId, editedLanguageVersions.Keys.Select(x => x.langId).ToList())
1102-
.WhereIn<DocumentCultureVariationDto>(x => x.NodeId, editedLanguageVersions.Keys.Select(x => x.nodeId))))
1103-
//convert to dictionary with the same key type
1104-
.ToDictionary(x => (x.NodeId, (int?)x.LanguageId), x => x);
1097+
// lookup all matching rows in umbracoDocumentCultureVariation
1098+
// fetch in batches to account for maximum parameter count (distinct languages can't exceed 2000)
1099+
var languageIds = editedLanguageVersions.Keys.Select(x => x.langId).Distinct().ToArray();
1100+
var nodeIds = editedLanguageVersions.Keys.Select(x => x.nodeId).Distinct();
1101+
var docCultureVariationsToUpdate = nodeIds.InGroupsOf(Constants.Sql.MaxParameterCount - languageIds.Length)
1102+
.SelectMany(group =>
1103+
{
1104+
var sql = Sql().Select<DocumentCultureVariationDto>().From<DocumentCultureVariationDto>()
1105+
.WhereIn<DocumentCultureVariationDto>(x => x.LanguageId, languageIds)
1106+
.WhereIn<DocumentCultureVariationDto>(x => x.NodeId, group);
1107+
1108+
return Database.Fetch<DocumentCultureVariationDto>(sql);
1109+
})
1110+
.ToDictionary(x => (x.NodeId, (int?)x.LanguageId), x => x); //convert to dictionary with the same key type
11051111

11061112
var toUpdate = new List<DocumentCultureVariationDto>();
11071113
foreach (var ev in editedLanguageVersions)

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,41 @@ public PermissionRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogg
3838
/// <param name="entityIds"></param>
3939
/// <returns></returns>
4040
/// <remarks>
41-
/// This method will not support passing in more than 2000 group Ids
41+
/// This method will not support passing in more than 2000 group IDs when also passing in entity IDs.
4242
/// </remarks>
4343
public EntityPermissionCollection GetPermissionsForEntities(int[] groupIds, params int[] entityIds)
4444
{
4545
var result = new EntityPermissionCollection();
4646

47-
foreach (var groupOfGroupIds in groupIds.InGroupsOf(Constants.Sql.MaxParameterCount))
47+
if (entityIds.Length == 0)
4848
{
49-
//copy local
50-
var localIds = groupOfGroupIds.ToArray();
51-
52-
if (entityIds.Length == 0)
49+
foreach (var group in groupIds.InGroupsOf(Constants.Sql.MaxParameterCount))
5350
{
5451
var sql = Sql()
5552
.SelectAll()
5653
.From<UserGroup2NodePermissionDto>()
57-
.Where<UserGroup2NodePermissionDto>(dto => localIds.Contains(dto.UserGroupId));
54+
.Where<UserGroup2NodePermissionDto>(dto => group.Contains(dto.UserGroupId));
55+
5856
var permissions = AmbientScope.Database.Fetch<UserGroup2NodePermissionDto>(sql);
5957
foreach (var permission in ConvertToPermissionList(permissions))
6058
{
6159
result.Add(permission);
6260
}
6361
}
64-
else
62+
}
63+
else
64+
{
65+
foreach (var group in entityIds.InGroupsOf(Constants.Sql.MaxParameterCount - groupIds.Length))
6566
{
66-
//iterate in groups of 2000 since we don't want to exceed the max SQL param count
67-
foreach (var groupOfEntityIds in entityIds.InGroupsOf(Constants.Sql.MaxParameterCount))
67+
var sql = Sql()
68+
.SelectAll()
69+
.From<UserGroup2NodePermissionDto>()
70+
.Where<UserGroup2NodePermissionDto>(dto => groupIds.Contains(dto.UserGroupId) && group.Contains(dto.NodeId));
71+
72+
var permissions = AmbientScope.Database.Fetch<UserGroup2NodePermissionDto>(sql);
73+
foreach (var permission in ConvertToPermissionList(permissions))
6874
{
69-
var ids = groupOfEntityIds;
70-
var sql = Sql()
71-
.SelectAll()
72-
.From<UserGroup2NodePermissionDto>()
73-
.Where<UserGroup2NodePermissionDto>(dto => localIds.Contains(dto.UserGroupId) && ids.Contains(dto.NodeId));
74-
var permissions = AmbientScope.Database.Fetch<UserGroup2NodePermissionDto>(sql);
75-
foreach (var permission in ConvertToPermissionList(permissions))
76-
{
77-
result.Add(permission);
78-
}
75+
result.Add(permission);
7976
}
8077
}
8178
}

0 commit comments

Comments
 (0)