Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DistinctBy to avoid duplications #10677

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1095,14 +1095,32 @@ private void RenormalizeDocumentEditedFlags(IReadOnlyCollection<int> propertyTyp
}
}

//lookup all matching rows in umbracoDocumentCultureVariation
var docCultureVariationsToUpdate = editedLanguageVersions.InGroupsOf(2000)
.SelectMany(_ => Database.Fetch<DocumentCultureVariationDto>(
Sql().Select<DocumentCultureVariationDto>().From<DocumentCultureVariationDto>()
.WhereIn<DocumentCultureVariationDto>(x => x.LanguageId, editedLanguageVersions.Keys.Select(x => x.langId).ToList())
.WhereIn<DocumentCultureVariationDto>(x => x.NodeId, editedLanguageVersions.Keys.Select(x => x.nodeId))))
//convert to dictionary with the same key type
.ToDictionary(x => (x.NodeId, (int?)x.LanguageId), x => x);
// lookup all matching rows in umbracoDocumentCultureVariation in groups
var editedLanguageVersionsInGroups = editedLanguageVersions.InGroupsOf(1000);

var docCultureVariationsToUpdate = new Dictionary<(int NodeId, int? LanguageId), DocumentCultureVariationDto>();

foreach (var editedLanguageVersionsGroup in editedLanguageVersionsInGroups)
{
var group = editedLanguageVersionsGroup.ToList();
var nodeIds = group.Select(keyValuePair => keyValuePair.Key.nodeId);

var sql = Sql().Select<DocumentCultureVariationDto>().From<DocumentCultureVariationDto>()
.WhereIn<DocumentCultureVariationDto>(x => x.LanguageId,
editedLanguageVersions.Keys.Select(x => x.langId).ToList())
.WhereIn<DocumentCultureVariationDto>(x => x.NodeId,
nodeIds);

var docCultureVariationsToUpdatePerGroup = group.SelectMany(_ =>
Database.Fetch<DocumentCultureVariationDto>(sql))
.DistinctBy(x => (x.NodeId, (int?)x.LanguageId))
.ToDictionary(x => (x.NodeId, (int?)x.LanguageId), x => x);


docCultureVariationsToUpdate = docCultureVariationsToUpdate.Concat(docCultureVariationsToUpdatePerGroup.Where(x => !docCultureVariationsToUpdate.ContainsKey(x.Key)))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

}

var toUpdate = new List<DocumentCultureVariationDto>();
foreach (var ev in editedLanguageVersions)
Expand Down