From ccd02cf2a99c37b9f314f74bd55370231f7d1be8 Mon Sep 17 00:00:00 2001 From: Matthew Care Date: Wed, 9 Oct 2024 08:39:22 +0200 Subject: [PATCH] Fix internal class being returned from media cache service (#17213) * update backoffice submodule * update backoffice submodule * Fix internal class being returned from media cache service Return the correct models from the media cache service --------- Co-authored-by: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> --- .../Services/MediaCacheService.cs | 15 ++++++++++----- src/Umbraco.Web.UI.Client | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs b/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs index 78e456dbf0..e100917346 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Services/MediaCacheService.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Caching.Hybrid; +using Microsoft.Extensions.Caching.Hybrid; using Microsoft.Extensions.Options; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; @@ -8,6 +8,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Infrastructure.HybridCache.Factories; using Umbraco.Cms.Infrastructure.HybridCache.Persistence; using Umbraco.Cms.Infrastructure.HybridCache.Serialization; +using Umbraco.Extensions; namespace Umbraco.Cms.Infrastructure.HybridCache.Services; @@ -20,6 +21,7 @@ internal class MediaCacheService : IMediaCacheService private readonly IPublishedContentFactory _publishedContentFactory; private readonly ICacheNodeFactory _cacheNodeFactory; private readonly IEnumerable _seedKeyProviders; + private readonly IPublishedModelFactory _publishedModelFactory; private readonly CacheSettings _cacheSettings; private HashSet? _seedKeys; @@ -51,6 +53,7 @@ internal class MediaCacheService : IMediaCacheService IPublishedContentFactory publishedContentFactory, ICacheNodeFactory cacheNodeFactory, IEnumerable seedKeyProviders, + IPublishedModelFactory publishedModelFactory, IOptions cacheSettings) { _databaseCacheRepository = databaseCacheRepository; @@ -60,6 +63,7 @@ internal class MediaCacheService : IMediaCacheService _publishedContentFactory = publishedContentFactory; _cacheNodeFactory = cacheNodeFactory; _seedKeyProviders = seedKeyProviders; + _publishedModelFactory = publishedModelFactory; _cacheSettings = cacheSettings.Value; } @@ -78,7 +82,7 @@ internal class MediaCacheService : IMediaCacheService async cancel => await _databaseCacheRepository.GetMediaSourceAsync(idAttempt.Result)); scope.Complete(); - return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode); + return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode).CreateModel(_publishedModelFactory); } public async Task GetByIdAsync(int id) @@ -94,7 +98,7 @@ internal class MediaCacheService : IMediaCacheService $"{keyAttempt.Result}", // Unique key to the cache entry async cancel => await _databaseCacheRepository.GetMediaSourceAsync(id)); scope.Complete(); - return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode); + return contentCacheNode is null ? null : _publishedContentFactory.ToIPublishedMedia(contentCacheNode).CreateModel(_publishedModelFactory); } public async Task HasContentByIdAsync(int id) @@ -144,7 +148,7 @@ internal class MediaCacheService : IMediaCacheService foreach (Guid key in SeedKeys) { - if(cancellationToken.IsCancellationRequested) + if (cancellationToken.IsCancellationRequested) { break; } @@ -187,7 +191,8 @@ internal class MediaCacheService : IMediaCacheService private HybridCacheEntryOptions GetSeedEntryOptions() => new() { - Expiration = _cacheSettings.SeedCacheDuration, LocalCacheExpiration = _cacheSettings.SeedCacheDuration, + Expiration = _cacheSettings.SeedCacheDuration, + LocalCacheExpiration = _cacheSettings.SeedCacheDuration, }; private string GetCacheKey(Guid key, bool preview) => preview ? $"{key}+draft" : $"{key}"; diff --git a/src/Umbraco.Web.UI.Client b/src/Umbraco.Web.UI.Client index 7d5d6558e3..00e5576244 160000 --- a/src/Umbraco.Web.UI.Client +++ b/src/Umbraco.Web.UI.Client @@ -1 +1 @@ -Subproject commit 7d5d6558e3532f18d1220983e11ee19fceea745d +Subproject commit 00e5576244a11e0fc1ea9aa2b79d3deba04e1609