From e9cbea585108b882d8534057f568dcdf1689b2fc Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Tue, 1 Oct 2024 20:26:41 +0200 Subject: [PATCH] Fixes issues with database rebuild and the fact media was created as published. Leading to cache misses --- .../DatabaseCacheRebuilder.cs | 12 ++++++++++-- .../Persistence/DatabaseCacheRepository.cs | 18 ++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs index 8d2fe9a04f7d..38a385890482 100644 --- a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs +++ b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs @@ -1,4 +1,5 @@ using Umbraco.Cms.Core.PublishedCache; +using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Infrastructure.HybridCache.Persistence; namespace Umbraco.Cms.Infrastructure.HybridCache; @@ -6,11 +7,18 @@ namespace Umbraco.Cms.Infrastructure.HybridCache; internal class DatabaseCacheRebuilder : IDatabaseCacheRebuilder { private readonly IDatabaseCacheRepository _databaseCacheRepository; + private readonly ICoreScopeProvider _coreScopeProvider; - public DatabaseCacheRebuilder(IDatabaseCacheRepository databaseCacheRepository) + public DatabaseCacheRebuilder(IDatabaseCacheRepository databaseCacheRepository, ICoreScopeProvider coreScopeProvider) { _databaseCacheRepository = databaseCacheRepository; + _coreScopeProvider = coreScopeProvider; } - public void Rebuild() => _databaseCacheRepository.Rebuild(); + public void Rebuild() + { + using ICoreScope scope = _coreScopeProvider.CreateCoreScope(); + _databaseCacheRepository.Rebuild(); + scope.Complete(); + } } diff --git a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs index 0f917508aa72..fd3d64e0f557 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Persistence/DatabaseCacheRepository.cs @@ -87,7 +87,7 @@ public async Task RefreshContentAsync(ContentCacheNode contentCacheNode, Publish public async Task RefreshMediaAsync(ContentCacheNode contentCacheNode) { IContentCacheDataSerializer serializer = _contentCacheDataSerializerFactory.Create(ContentCacheDataSerializerEntityType.Media); - await OnRepositoryRefreshed(serializer, contentCacheNode, false); + await OnRepositoryRefreshed(serializer, contentCacheNode, true); } /// @@ -117,20 +117,10 @@ public void Rebuild( } } - if (contentTypeIds != null) - { - RebuildContentDbCache(serializer, _nucacheSettings.Value.SqlPageSize, contentTypeIds); - } + RebuildContentDbCache(serializer, _nucacheSettings.Value.SqlPageSize, contentTypeIds); + RebuildMediaDbCache(serializer, _nucacheSettings.Value.SqlPageSize, mediaTypeIds); + RebuildMemberDbCache(serializer, _nucacheSettings.Value.SqlPageSize, memberTypeIds); - if (mediaTypeIds != null) - { - RebuildMediaDbCache(serializer, _nucacheSettings.Value.SqlPageSize, mediaTypeIds); - } - - if (memberTypeIds != null) - { - RebuildMemberDbCache(serializer, _nucacheSettings.Value.SqlPageSize, memberTypeIds); - } } // assumes content tree lock