Skip to content

Commit 20c29f8

Browse files
authored
V17 - Removed obsoleted code from Umbraco.Cms.Core.Cache & .Routing (#19959)
* Removing obsoleted code from ApiMediaQueryService.cs * Removing obsoleted code from ApiRichTextMarkupParserTests.cs * Removing obsoleted code from ContentCacheRefresher.cs * Removing obsoleted code from ContentFinderByUrlAlias.cs and adjusting its tests to use the new logic * Removing obsoleted code from ContentFinderByUrl.cs & its dependencies * Removing obsoleted code from ApiRichTextMarkupParserTests.cs * Removing obsoleted code from DocumentCache.cs & its dependencies * Removing obsoleted code from MediaCache.cs & its dependencies * Removing obsoleted code from PublishedCacheBase.cs & its dependencies * Removing obsoleted code from RenderNoContentController.cs and its tests * Removing obsoleted code from UmbracoRouteValueTransformer.cs * Removing obsoleted constructors from DefaultUrlProvider.cs * Removing accidental bookmark * Introducing a helper method to get the root keys in ApiMediaQueryService.cs * Removing obsoleted code from Cache classes * Removing unused imports * Refactoring to meet the CR * Added attribute to controller * Fixing missing using statement
1 parent b8ca11e commit 20c29f8

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

src/Umbraco.Cms.Api.Delivery/Services/ApiMediaQueryService.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ private IPublishedMediaCache GetRequiredPublishedMediaCache()
6666
private IPublishedContent? TryGetByPath(string path, IPublishedMediaCache mediaCache)
6767
{
6868
var segments = path.Split(Constants.CharArrays.ForwardSlash, StringSplitOptions.RemoveEmptyEntries);
69-
if (_mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys) is false)
70-
{
71-
return null;
72-
}
73-
74-
IEnumerable<IPublishedContent> currentChildren = rootKeys.Select(x => mediaCache.GetById(false, x)).WhereNotNull();
69+
IEnumerable<IPublishedContent> currentChildren = GetRootContent(mediaCache);
7570
IPublishedContent? resolvedMedia = null;
7671

7772
foreach (var segment in segments)
@@ -106,9 +101,9 @@ private IPublishedMediaCache GetRequiredPublishedMediaCache()
106101
}
107102

108103
IPublishedMediaCache mediaCache = GetRequiredPublishedMediaCache();
109-
if (childrenOf.Trim(Constants.CharArrays.ForwardSlash).Length == 0 && _mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys))
104+
if (childrenOf.Trim(Constants.CharArrays.ForwardSlash).Length == 0)
110105
{
111-
return rootKeys.Select(x => mediaCache.GetById(false, x)).WhereNotNull();
106+
return GetRootContent(mediaCache);
112107
}
113108

114109
IPublishedContent? parent = Guid.TryParse(childrenOf, out Guid parentKey)
@@ -201,4 +196,8 @@ private static Attempt<PagedModel<Guid>, ApiMediaQueryOperationStatus> PagedResu
201196

202197
return Attempt.SucceedWithStatus(ApiMediaQueryOperationStatus.Success, result);
203198
}
199+
200+
private IEnumerable<IPublishedContent> GetRootContent(IPublishedMediaCache mediaCache)
201+
=> _mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys) is false ? []
202+
: rootKeys.Select(x => mediaCache.GetById(false, x)).WhereNotNull();
204203
}

src/Umbraco.PublishedCache.HybridCache/DocumentCache.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Umbraco.Cms.Core;
21
using Umbraco.Cms.Core.Models.PublishedContent;
32
using Umbraco.Cms.Core.PublishedCache;
43
using Umbraco.Cms.Core.Routing;
@@ -45,7 +44,10 @@ public DocumentCache(
4544

4645
public IEnumerable<IPublishedContent> GetAtRoot(bool preview, string? culture = null)
4746
{
48-
_documentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
47+
if (_documentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys) is false)
48+
{
49+
return [];
50+
}
4951

5052
IEnumerable<IPublishedContent> rootContent = rootKeys.Select(key => GetById(preview, key)).WhereNotNull();
5153
return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture));

src/Umbraco.PublishedCache.HybridCache/MediaCache.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Umbraco.Cms.Core;
21
using Umbraco.Cms.Core.Models.PublishedContent;
32
using Umbraco.Cms.Core.PublishedCache;
43
using Umbraco.Cms.Core.Services.Navigation;
@@ -35,7 +34,10 @@ public MediaCache(IMediaCacheService mediaCacheService, IPublishedContentTypeCac
3534

3635
public IEnumerable<IPublishedContent> GetAtRoot(bool preview, string? culture = null)
3736
{
38-
_mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
37+
if (_mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys) is false)
38+
{
39+
return [];
40+
}
3941

4042
IEnumerable<IPublishedContent> rootContent = rootKeys.Select(key => GetById(preview, key)).WhereNotNull();
4143
return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture));

tests/Umbraco.Tests.UnitTests/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformerTests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System.Reflection;
2-
using System.Threading.Tasks;
3-
using Lucene.Net.Search.Similarities;
42
using Microsoft.AspNetCore.DataProtection;
53
using Microsoft.AspNetCore.Http;
64
using Microsoft.AspNetCore.Mvc.Controllers;
@@ -13,15 +11,11 @@
1311
using NUnit.Framework;
1412
using Umbraco.Cms.Core;
1513
using Umbraco.Cms.Core.Configuration.Models;
16-
using Umbraco.Cms.Core.Events;
1714
using Umbraco.Cms.Core.Models.PublishedContent;
18-
using Umbraco.Cms.Core.PublishedCache;
1915
using Umbraco.Cms.Core.Routing;
2016
using Umbraco.Cms.Core.Services;
2117
using Umbraco.Cms.Core.Web;
22-
using Umbraco.Cms.Tests.UnitTests.TestHelpers;
2318
using Umbraco.Cms.Web.Common.Controllers;
24-
using Umbraco.Cms.Web.Common.Filters;
2519
using Umbraco.Cms.Web.Common.Routing;
2620
using Umbraco.Cms.Web.Website.Controllers;
2721
using Umbraco.Cms.Web.Website.Routing;

0 commit comments

Comments
 (0)