From f95739fa5d65ba62eeb825b6b18f31a7ba25ea5c Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Tue, 22 Apr 2025 15:43:34 +0200 Subject: [PATCH] Avoids unnecessary additional domain save notification publishings when sorting an already sorted collection of domains. --- src/Umbraco.Core/Services/DomainService.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Core/Services/DomainService.cs b/src/Umbraco.Core/Services/DomainService.cs index 202d51d64874..03ebac92c5a8 100644 --- a/src/Umbraco.Core/Services/DomainService.cs +++ b/src/Umbraco.Core/Services/DomainService.cs @@ -108,7 +108,7 @@ public IEnumerable GetAssignedDomains(int contentId, bool includeWildca EventMessages eventMessages = EventMessagesFactory.Get(); IDomain[] domains = items.ToArray(); - if (domains.Length == 0) + if (domains.Length == 0 || AreDomainsAlreadySorted(domains)) { return OperationResult.Attempt.NoOperation(eventMessages); } @@ -144,4 +144,18 @@ public IEnumerable GetAssignedDomains(int contentId, bool includeWildca return OperationResult.Attempt.Succeed(eventMessages); } + + private static bool AreDomainsAlreadySorted(IDomain[] domains) + { + // Check if the domains are already sorted by comparing the current sort order with what we'll set to be the new sort order. + for (int i = 0; i < domains.Length; i++) + { + if (domains[i].SortOrder != i) + { + return false; + } + } + + return true; + } }