Skip to content

Commit 0fc5b2a

Browse files
authored
Avoids unnecessary additional domain save notification publishing when sorting an already sorted collection of domains (#19106)
Avoids unnecessary additional domain save notification publishings when sorting an already sorted collection of domains.
1 parent 6c2f93e commit 0fc5b2a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Umbraco.Core/Services/DomainService.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public IEnumerable<IDomain> GetAssignedDomains(int contentId, bool includeWildca
108108
EventMessages eventMessages = EventMessagesFactory.Get();
109109

110110
IDomain[] domains = items.ToArray();
111-
if (domains.Length == 0)
111+
if (domains.Length == 0 || AreDomainsAlreadySorted(domains))
112112
{
113113
return OperationResult.Attempt.NoOperation(eventMessages);
114114
}
@@ -144,4 +144,18 @@ public IEnumerable<IDomain> GetAssignedDomains(int contentId, bool includeWildca
144144

145145
return OperationResult.Attempt.Succeed(eventMessages);
146146
}
147+
148+
private static bool AreDomainsAlreadySorted(IDomain[] domains)
149+
{
150+
// Check if the domains are already sorted by comparing the current sort order with what we'll set to be the new sort order.
151+
for (int i = 0; i < domains.Length; i++)
152+
{
153+
if (domains[i].SortOrder != i)
154+
{
155+
return false;
156+
}
157+
}
158+
159+
return true;
160+
}
147161
}

0 commit comments

Comments
 (0)