Skip to content

Commit

Permalink
Fixes routing issues based on findings #17572 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergmania committed Nov 20, 2024
1 parent 5ba2103 commit ba7fb5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/Umbraco.Core/Services/DocumentUrlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ private string GetFullUrl(bool isRootFirstItem, List<string> segments, Domain? f
return foundDomain.Name.EnsureEndsWith("/") + string.Join('/', urlSegments);
}

var hideTopLevel = _globalSettings.HideTopLevelNodeFromPath && isRootFirstItem;
// We always hide the top level of the first root item and decesendants
var hideTopLevel = _globalSettings.HideTopLevelNodeFromPath || isRootFirstItem;
if (leftToRight)
{
return '/' + string.Join('/', urlSegments.Skip(hideTopLevel ? 1 : 0));
Expand Down Expand Up @@ -735,12 +736,33 @@ private IEnumerable<Guid> GetKeysInRoot(bool considerFirstLevelAsRoot, bool isDr
}
else
{
Guid? firstRoot = null;
foreach (Guid rootKey in rootKeys)
{
if (isDraft is false && IsContentPublished(rootKey, culture) is false)
{
continue;
}

if (firstRoot is null)
{
firstRoot = rootKey;
}

yield return rootKey;
}
}

//Always consider the child of first root item as roots
if (firstRoot.HasValue)
{
IEnumerable<Guid> childKeys = GetChildKeys(firstRoot.Value);

foreach (Guid childKey in childKeys)
{
yield return childKey;
}
}
}

Check warning on line 765 in src/Umbraco.Core/Services/DocumentUrlService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)

❌ Getting worse: Complex Method

GetKeysInRoot increases in cyclomatic complexity from 10 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 765 in src/Umbraco.Core/Services/DocumentUrlService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)

❌ New issue: Bumpy Road Ahead

GetKeysInRoot has 3 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
}

private Guid? GetChildWithUrlSegment(IEnumerable<Guid> childKeys, string urlSegment, string culture, bool isDraft)
Expand Down
1 change: 0 additions & 1 deletion src/Umbraco.Core/Services/IDocumentUrlService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Umbraco.Cms.Core.Media.EmbedProviders;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Routing;

Expand Down

0 comments on commit ba7fb5c

Please sign in to comment.