diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Installer.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Installer.cs index a5cf808b2e26..885b8b65b0a9 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Installer.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Installer.cs @@ -20,6 +20,7 @@ internal static IUmbracoBuilder AddInstaller(this IUmbracoBuilder builder) // Add post migration notification handlers builder.AddNotificationHandler(); + return builder; } } diff --git a/src/Umbraco.Infrastructure/Install/UnattendedUpgrader.cs b/src/Umbraco.Infrastructure/Install/UnattendedUpgrader.cs index 54f550f23258..11e7836e9e26 100644 --- a/src/Umbraco.Infrastructure/Install/UnattendedUpgrader.cs +++ b/src/Umbraco.Infrastructure/Install/UnattendedUpgrader.cs @@ -1,6 +1,8 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core; +using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DependencyInjection; @@ -28,7 +30,10 @@ public class UnattendedUpgrader : INotificationAsyncHandler _logger; + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 19.")] public UnattendedUpgrader( IProfilingLogger profilingLogger, IUmbracoVersion umbracoVersion, @@ -36,13 +41,36 @@ public UnattendedUpgrader( IRuntimeState runtimeState, PackageMigrationRunner packageMigrationRunner, IOptions unattendedSettings) + : this( + profilingLogger, + umbracoVersion, + databaseBuilder, + runtimeState, + packageMigrationRunner, + unattendedSettings, + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService>()) { - _profilingLogger = profilingLogger ?? throw new ArgumentNullException(nameof(profilingLogger)); - _umbracoVersion = umbracoVersion ?? throw new ArgumentNullException(nameof(umbracoVersion)); - _databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder)); - _runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); + } + + public UnattendedUpgrader( + IProfilingLogger profilingLogger, + IUmbracoVersion umbracoVersion, + DatabaseBuilder databaseBuilder, + IRuntimeState runtimeState, + PackageMigrationRunner packageMigrationRunner, + IOptions unattendedSettings, + DistributedCache distributedCache, + ILogger logger) + { + _profilingLogger = profilingLogger; + _umbracoVersion = umbracoVersion; + _databaseBuilder = databaseBuilder; + _runtimeState = runtimeState; _packageMigrationRunner = packageMigrationRunner; _unattendedSettings = unattendedSettings.Value; + _distributedCache = distributedCache; + _logger = logger; } public async Task HandleAsync(RuntimeUnattendedUpgradeNotification notification, CancellationToken cancellationToken) @@ -109,8 +137,13 @@ private async Task RunPackageMigrationsAsync(RuntimeUnattendedUpgradeNotificatio try { await _packageMigrationRunner.RunPackagePlansAsync(pendingMigrations); - notification.UnattendedUpgradeResult = RuntimeUnattendedUpgradeNotification.UpgradeResult - .PackageMigrationComplete; + notification.UnattendedUpgradeResult = RuntimeUnattendedUpgradeNotification.UpgradeResult.PackageMigrationComplete; + + // Migration plans may have changed published content, so refresh the distributed cache to ensure consistency on first request. + _distributedCache.RefreshAllPublishedSnapshot(); + _logger.LogInformation( + "Migration plans run: {Plans}. Triggered refresh of distributed published content cache.", + string.Join(", ", pendingMigrations)); } catch (Exception ex) { diff --git a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs index 5b1512ef5049..670a004d896d 100644 --- a/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs +++ b/src/Umbraco.PublishedCache.HybridCache/DatabaseCacheRebuilder.cs @@ -108,7 +108,7 @@ public async Task RebuildDatabaseCacheIfSerializerChangedAsync() _logger.LogWarning( "Database cache was serialized using {CurrentSerializer}. Currently configured cache serializer {Serializer}. Rebuilding database cache.", - currentSerializer, + currentSerializer == 0 ? "None" : currentSerializer, serializer); using (_profilingLogger.TraceDuration($"Rebuilding database cache with {serializer} serializer")) diff --git a/src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs b/src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs index 68f4d8d80fcb..a22ce1d07d3f 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs @@ -38,7 +38,7 @@ public PublishedContentFactory( /// public IPublishedContent? ToIPublishedContent(ContentCacheNode contentCacheNode, bool preview) { - var cacheKey = $"{nameof(PublishedContentFactory)}DocumentCache_{contentCacheNode.Id}_{preview}"; + var cacheKey = $"{nameof(PublishedContentFactory)}DocumentCache_{contentCacheNode.Id}_{preview}_{contentCacheNode.Data?.VersionDate.Ticks ?? 0}"; IPublishedContent? publishedContent = null; if (_appCaches.RequestCache.IsAvailable) {