Skip to content

Commit 5ef013c

Browse files
author
nikolajlauridsen
committed
Ensure ContentType is only marked as dirty when it's actually changed
1 parent 1cdc6f0 commit 5ef013c

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void Map(DocumentTypeSave source, IContentType target, MapperContext con
133133

134134
if (target is IContentTypeWithHistoryCleanup targetWithHistoryCleanup)
135135
{
136-
targetWithHistoryCleanup.HistoryCleanup = source.HistoryCleanup;
136+
MapHistoryCleanup(source, targetWithHistoryCleanup);
137137
}
138138

139139
target.AllowedTemplates = source.AllowedTemplates
@@ -147,6 +147,34 @@ private void Map(DocumentTypeSave source, IContentType target, MapperContext con
147147
: _fileService.GetTemplate(source.DefaultTemplate));
148148
}
149149

150+
private static void MapHistoryCleanup(DocumentTypeSave source, IContentTypeWithHistoryCleanup target)
151+
{
152+
// If source history cleanup is null we don't have to map all properties
153+
if (source.HistoryCleanup is null)
154+
{
155+
target.HistoryCleanup = null;
156+
return;
157+
}
158+
159+
// We need to reset the dirty properties, because it is otherwise true, just because the json serializer has set properties
160+
target.HistoryCleanup.ResetDirtyProperties(false);
161+
if (target.HistoryCleanup.PreventCleanup != source.HistoryCleanup.PreventCleanup)
162+
{
163+
target.HistoryCleanup.PreventCleanup = source.HistoryCleanup.PreventCleanup;
164+
}
165+
166+
if (target.HistoryCleanup.KeepAllVersionsNewerThanDays != source.HistoryCleanup.KeepAllVersionsNewerThanDays)
167+
{
168+
target.HistoryCleanup.KeepAllVersionsNewerThanDays = source.HistoryCleanup.KeepAllVersionsNewerThanDays;
169+
}
170+
171+
if (target.HistoryCleanup.KeepLatestVersionPerDayForDays !=
172+
source.HistoryCleanup.KeepLatestVersionPerDayForDays)
173+
{
174+
target.HistoryCleanup.KeepLatestVersionPerDayForDays = source.HistoryCleanup.KeepLatestVersionPerDayForDays;
175+
}
176+
}
177+
150178
// no MapAll - take care
151179
private void Map(MediaTypeSave source, IMediaType target, MapperContext context)
152180
{
@@ -328,7 +356,10 @@ private static void Map(PropertyTypeBasic source, IPropertyType target, MapperCo
328356

329357
if (source.GroupId > 0)
330358
{
331-
target.PropertyGroupId = new Lazy<int>(() => source.GroupId, false);
359+
if (target.PropertyGroupId?.Value != source.GroupId)
360+
{
361+
target.PropertyGroupId = new Lazy<int>(() => source.GroupId, false);
362+
}
332363
}
333364

334365
target.Alias = source.Alias;
@@ -523,7 +554,15 @@ private static void MapSaveToTypeBase<TSource, TSourcePropertyType>(TSource sour
523554
target.Thumbnail = source.Thumbnail;
524555

525556
target.AllowedAsRoot = source.AllowAsRoot;
526-
target.AllowedContentTypes = source.AllowedContentTypes.Select((t, i) => new ContentTypeSort(t, i));
557+
558+
bool allowedContentTypesUnchanged = target.AllowedContentTypes.Select(x => x.Id.Value)
559+
.SequenceEqual(source.AllowedContentTypes);
560+
561+
if (allowedContentTypesUnchanged is false)
562+
{
563+
target.AllowedContentTypes = source.AllowedContentTypes.Select((t, i) => new ContentTypeSort(t, i));
564+
}
565+
527566

528567
if (!(target is IMemberType))
529568
{
@@ -574,13 +613,21 @@ private static void MapSaveToTypeBase<TSource, TSourcePropertyType>(TSource sour
574613

575614
// ensure no duplicate alias, then assign the group properties collection
576615
EnsureUniqueAliases(destProperties);
577-
destGroup.PropertyTypes = new PropertyTypeCollection(isPublishing, destProperties);
616+
if (destGroup.PropertyTypes.SupportsPublishing != isPublishing || destGroup.PropertyTypes.SequenceEqual(destProperties) is false)
617+
{
618+
destGroup.PropertyTypes = new PropertyTypeCollection(isPublishing, destProperties);
619+
}
620+
578621
destGroups.Add(destGroup);
579622
}
580623

581624
// ensure no duplicate name, then assign the groups collection
582625
EnsureUniqueAliases(destGroups);
583-
target.PropertyGroups = new PropertyGroupCollection(destGroups);
626+
627+
if (target.PropertyGroups.SequenceEqual(destGroups) is false)
628+
{
629+
target.PropertyGroups = new PropertyGroupCollection(destGroups);
630+
}
584631

585632
// because the property groups collection was rebuilt, there is no need to remove
586633
// the old groups - they are just gone and will be cleared by the repository

0 commit comments

Comments
 (0)