V15: Implement not-implemented methods for media cache (#17524)
* Implement not-implemented methods for media cache * Fixed test --------- Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -26,4 +26,5 @@ public interface IMediaCacheService
|
||||
Task SeedAsync(CancellationToken cancellationToken);
|
||||
|
||||
void Rebuild(IReadOnlyCollection<int> contentTypeIds);
|
||||
IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType);
|
||||
}
|
||||
|
||||
@@ -14,11 +14,22 @@ public sealed class DocumentCache : IPublishedContentCache
|
||||
{
|
||||
private readonly IDocumentCacheService _documentCacheService;
|
||||
private readonly IPublishedContentTypeCache _publishedContentTypeCache;
|
||||
private readonly IDocumentNavigationQueryService _documentNavigationQueryService;
|
||||
private readonly IDocumentUrlService _documentUrlService;
|
||||
private readonly Lazy<IPublishedUrlProvider> _publishedUrlProvider;
|
||||
|
||||
public DocumentCache(IDocumentCacheService documentCacheService, IPublishedContentTypeCache publishedContentTypeCache)
|
||||
public DocumentCache(
|
||||
IDocumentCacheService documentCacheService,
|
||||
IPublishedContentTypeCache publishedContentTypeCache,
|
||||
IDocumentNavigationQueryService documentNavigationQueryService,
|
||||
IDocumentUrlService documentUrlService,
|
||||
Lazy<IPublishedUrlProvider> publishedUrlProvider)
|
||||
{
|
||||
_documentCacheService = documentCacheService;
|
||||
_publishedContentTypeCache = publishedContentTypeCache;
|
||||
_documentNavigationQueryService = documentNavigationQueryService;
|
||||
_documentUrlService = documentUrlService;
|
||||
_publishedUrlProvider = publishedUrlProvider;
|
||||
}
|
||||
|
||||
public async Task<IPublishedContent?> GetByIdAsync(int id, bool? preview = null) => await _documentCacheService.GetByIdAsync(id, preview);
|
||||
@@ -65,21 +76,17 @@ public sealed class DocumentCache : IPublishedContentCache
|
||||
return GetById(guidUdi.Guid);
|
||||
}
|
||||
|
||||
[Obsolete("Scheduled for removal, use IDocumentNavigationQueryService instead in v17")]
|
||||
public IEnumerable<IPublishedContent> GetAtRoot(bool preview, string? culture = null)
|
||||
{
|
||||
IDocumentNavigationQueryService navigationService = StaticServiceProvider.Instance.GetRequiredService<IDocumentNavigationQueryService>();
|
||||
navigationService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
|
||||
_documentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
|
||||
|
||||
IEnumerable<IPublishedContent> rootContent = rootKeys.Select(key => GetById(preview, key)).WhereNotNull();
|
||||
return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture));
|
||||
}
|
||||
|
||||
[Obsolete("Scheduled for removal, use IDocumentNavigationQueryService instead in v17")]
|
||||
public IEnumerable<IPublishedContent> GetAtRoot(string? culture = null)
|
||||
{
|
||||
IDocumentNavigationQueryService navigationService = StaticServiceProvider.Instance.GetRequiredService<IDocumentNavigationQueryService>();
|
||||
navigationService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
|
||||
_documentNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
|
||||
|
||||
IEnumerable<IPublishedContent> rootContent = rootKeys.Select(key => GetById(key)).WhereNotNull();
|
||||
return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture));
|
||||
@@ -89,7 +96,7 @@ public sealed class DocumentCache : IPublishedContentCache
|
||||
public bool HasContent(bool preview) => HasContent();
|
||||
|
||||
[Obsolete("Scheduled for removal in v17")]
|
||||
public bool HasContent() => StaticServiceProvider.Instance.GetRequiredService<IDocumentUrlService>().HasAny();
|
||||
public bool HasContent() => _documentUrlService.HasAny();
|
||||
|
||||
[Obsolete]
|
||||
public IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
|
||||
@@ -98,26 +105,23 @@ public sealed class DocumentCache : IPublishedContentCache
|
||||
[Obsolete("Use IPublishedUrlProvider.GetUrl instead, scheduled for removal in v17")]
|
||||
public IPublishedContent? GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string? culture = null)
|
||||
{
|
||||
IDocumentUrlService documentUrlService = StaticServiceProvider.Instance.GetRequiredService<IDocumentUrlService>();
|
||||
Guid? key = documentUrlService.GetDocumentKeyByRoute(route, culture, null, preview);
|
||||
Guid? key = _documentUrlService.GetDocumentKeyByRoute(route, culture, null, preview);
|
||||
return key is not null ? GetById(preview, key.Value) : null;
|
||||
}
|
||||
|
||||
[Obsolete("Use IPublishedUrlProvider.GetUrl instead, scheduled for removal in v17")]
|
||||
public IPublishedContent? GetByRoute(string route, bool? hideTopLevelNode = null, string? culture = null)
|
||||
{
|
||||
IDocumentUrlService documentUrlService = StaticServiceProvider.Instance.GetRequiredService<IDocumentUrlService>();
|
||||
Guid? key = documentUrlService.GetDocumentKeyByRoute(route, culture, null, false);
|
||||
Guid? key = _documentUrlService.GetDocumentKeyByRoute(route, culture, null, false);
|
||||
return key is not null ? GetById(key.Value) : null;
|
||||
}
|
||||
|
||||
[Obsolete("Use IPublishedUrlProvider.GetUrl instead, scheduled for removal in v17")]
|
||||
public string? GetRouteById(bool preview, int contentId, string? culture = null)
|
||||
{
|
||||
IPublishedUrlProvider publishedUrlProvider = StaticServiceProvider.Instance.GetRequiredService<IPublishedUrlProvider>();
|
||||
IPublishedContent? content = GetById(preview, contentId);
|
||||
|
||||
return content is not null ? publishedUrlProvider.GetUrl(content, UrlMode.Relative, culture) : null;
|
||||
return content is not null ? _publishedUrlProvider.Value.GetUrl(content, UrlMode.Relative, culture) : null;
|
||||
}
|
||||
|
||||
[Obsolete("Use IPublishedUrlProvider.GetUrl instead, scheduled for removal in v17")]
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Infrastructure.HybridCache.Services;
|
||||
using Umbraco.Cms.Core.Services.Navigation;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.HybridCache;
|
||||
|
||||
public class MediaCache : IPublishedMediaCache
|
||||
public sealed class MediaCache : IPublishedMediaCache
|
||||
{
|
||||
private readonly IMediaCacheService _mediaCacheService;
|
||||
private readonly IPublishedContentTypeCache _publishedContentTypeCache;
|
||||
private readonly IMediaNavigationQueryService _mediaNavigationQueryService;
|
||||
|
||||
public MediaCache(IMediaCacheService mediaCacheService, IPublishedContentTypeCache publishedContentTypeCache)
|
||||
public MediaCache(IMediaCacheService mediaCacheService, IPublishedContentTypeCache publishedContentTypeCache, IMediaNavigationQueryService mediaNavigationQueryService)
|
||||
{
|
||||
_mediaCacheService = mediaCacheService;
|
||||
_publishedContentTypeCache = publishedContentTypeCache;
|
||||
_mediaNavigationQueryService = mediaNavigationQueryService;
|
||||
}
|
||||
|
||||
public async Task<IPublishedContent?> GetByIdAsync(int id) => await _mediaCacheService.GetByIdAsync(id);
|
||||
@@ -37,20 +40,53 @@ public class MediaCache : IPublishedMediaCache
|
||||
|
||||
public IPublishedContentType GetContentType(string alias) => _publishedContentTypeCache.Get(PublishedItemType.Media, alias);
|
||||
|
||||
// FIXME - these need to be removed when removing nucache
|
||||
public IPublishedContent? GetById(bool preview, Udi contentId) => throw new NotImplementedException();
|
||||
[Obsolete("Scheduled for removal in v17")]
|
||||
public IPublishedContent? GetById(bool preview, Udi contentId)
|
||||
{
|
||||
if(contentId is not GuidUdi guidUdi)
|
||||
{
|
||||
throw new NotSupportedException("Only GuidUdi is supported");
|
||||
}
|
||||
|
||||
public IPublishedContent? GetById(Udi contentId) => throw new NotImplementedException();
|
||||
return GetById(preview, guidUdi.Guid);
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> GetAtRoot(bool preview, string? culture = null) => throw new NotImplementedException();
|
||||
[Obsolete("Scheduled for removal in v17")]
|
||||
public IPublishedContent? GetById(Udi contentId)
|
||||
{
|
||||
if(contentId is not GuidUdi guidUdi)
|
||||
{
|
||||
throw new NotSupportedException("Only GuidUdi is supported");
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> GetAtRoot(string? culture = null) => throw new NotImplementedException();
|
||||
return GetById(guidUdi.Guid);
|
||||
}
|
||||
|
||||
public bool HasContent(bool preview) => throw new NotImplementedException();
|
||||
public IEnumerable<IPublishedContent> GetAtRoot(bool preview, string? culture = null)
|
||||
{
|
||||
_mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
|
||||
|
||||
public bool HasContent() => throw new NotImplementedException();
|
||||
IEnumerable<IPublishedContent> rootContent = rootKeys.Select(key => GetById(preview, key)).WhereNotNull();
|
||||
return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture));
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> GetAtRoot(string? culture = null)
|
||||
{
|
||||
_mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
|
||||
|
||||
IEnumerable<IPublishedContent> rootContent = rootKeys.Select(key => GetById(key)).WhereNotNull();
|
||||
return culture is null ? rootContent : rootContent.Where(x => x.IsInvariantOrHasCulture(culture));
|
||||
}
|
||||
|
||||
[Obsolete("Media does not support preview, this method will be removed in future versions")]
|
||||
public bool HasContent(bool preview) => HasContent();
|
||||
|
||||
public bool HasContent()
|
||||
{
|
||||
_mediaNavigationQueryService.TryGetRootKeys(out IEnumerable<Guid> rootKeys);
|
||||
return rootKeys.Any();
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType) =>
|
||||
throw new NotImplementedException();
|
||||
_mediaCacheService.GetByContentType(contentType);
|
||||
}
|
||||
|
||||
@@ -259,6 +259,17 @@ internal class MediaCacheService : IMediaCacheService
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
public IEnumerable<IPublishedContent> GetByContentType(IPublishedContentType contentType)
|
||||
{
|
||||
using ICoreScope scope = _scopeProvider.CreateCoreScope();
|
||||
IEnumerable<ContentCacheNode> nodes = _databaseCacheRepository.GetContentByContentTypeKey([contentType.Key], ContentCacheDataSerializerEntityType.Media);
|
||||
scope.Complete();
|
||||
|
||||
return nodes
|
||||
.Select(x => _publishedContentFactory.ToIPublishedContent(x, x.IsDraft).CreateModel(_publishedModelFactory))
|
||||
.WhereNotNull();
|
||||
}
|
||||
|
||||
private HybridCacheEntryOptions GetEntryOptions(Guid key)
|
||||
{
|
||||
if (SeedKeys.Contains(key))
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Models.ContentPublishing;
|
||||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Core.Routing;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Core.Services.Navigation;
|
||||
@@ -107,7 +108,11 @@ public class DocumentHybridCacheMockTests : UmbracoIntegrationTestWithContent
|
||||
GetRequiredService<IPublishedModelFactory>(),
|
||||
GetRequiredService<IPreviewService>());
|
||||
|
||||
_mockedCache = new DocumentCache(_mockDocumentCacheService, GetRequiredService<IPublishedContentTypeCache>());
|
||||
_mockedCache = new DocumentCache(_mockDocumentCacheService,
|
||||
GetRequiredService<IPublishedContentTypeCache>(),
|
||||
GetRequiredService<IDocumentNavigationQueryService>(),
|
||||
GetRequiredService<IDocumentUrlService>(),
|
||||
new Lazy<IPublishedUrlProvider>(GetRequiredService<IPublishedUrlProvider>));
|
||||
}
|
||||
|
||||
// We want to be able to alter the settings for the providers AFTER the test has started
|
||||
|
||||
Reference in New Issue
Block a user