fix broken migration abstraction, fixes restart after upgrade so the runtimestate is correct, fixes sql alter column migration to actually run if its nullable.
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
using System.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Logging;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
using Umbraco.Cms.Infrastructure.PublishedCache.Persistence;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
{
|
||||
@@ -13,55 +10,25 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
|
||||
/// </summary>
|
||||
public class NuCacheStartupHandler : INotificationHandler<UmbracoApplicationStartingNotification>
|
||||
{
|
||||
// TODO: Eventually we should kill this since at some stage we shouldn't even support JSON since we know
|
||||
// this is faster.
|
||||
|
||||
internal const string Nucache_Serializer_Key = "Umbraco.Web.PublishedCache.NuCache.Serializer";
|
||||
private const string JSON_SERIALIZER_VALUE = "JSON";
|
||||
private readonly IPublishedSnapshotService _service;
|
||||
private readonly IKeyValueService _keyValueService;
|
||||
private readonly IProfilingLogger _profilingLogger;
|
||||
private readonly ILogger<NuCacheStartupHandler> _logger;
|
||||
private readonly INuCacheContentService _nuCacheContentService;
|
||||
private readonly IRuntimeState _runtimeState;
|
||||
|
||||
public NuCacheStartupHandler(
|
||||
IPublishedSnapshotService service,
|
||||
IKeyValueService keyValueService,
|
||||
IProfilingLogger profilingLogger,
|
||||
ILogger<NuCacheStartupHandler> logger)
|
||||
INuCacheContentService nuCacheContentService,
|
||||
IRuntimeState runtimeState)
|
||||
{
|
||||
_service = service;
|
||||
_keyValueService = keyValueService;
|
||||
_profilingLogger = profilingLogger;
|
||||
_logger = logger;
|
||||
_nuCacheContentService = nuCacheContentService;
|
||||
_runtimeState = runtimeState;
|
||||
}
|
||||
|
||||
public void Handle(UmbracoApplicationStartingNotification notification)
|
||||
=> RebuildDatabaseCacheIfSerializerChanged();
|
||||
|
||||
private void RebuildDatabaseCacheIfSerializerChanged()
|
||||
{
|
||||
var serializer = ConfigurationManager.AppSettings[Nucache_Serializer_Key];
|
||||
var currentSerializer = _keyValueService.GetValue(Nucache_Serializer_Key);
|
||||
|
||||
if (currentSerializer == null)
|
||||
if (_runtimeState.Level == Core.RuntimeLevel.Run)
|
||||
{
|
||||
currentSerializer = JSON_SERIALIZER_VALUE;
|
||||
}
|
||||
if (serializer == null)
|
||||
{
|
||||
serializer = JSON_SERIALIZER_VALUE;
|
||||
}
|
||||
|
||||
if (serializer != currentSerializer)
|
||||
{
|
||||
_logger.LogWarning("Database NuCache was serialized using {CurrentSerializer}. Currently configured NuCache serializer {Serializer}. Rebuilding Nucache", currentSerializer, serializer);
|
||||
|
||||
using (_profilingLogger.TraceDuration<NuCacheStartupHandler>($"Rebuilding NuCache database with {currentSerializer} serializer"))
|
||||
{
|
||||
_service.Rebuild();
|
||||
_keyValueService.SetValue(Nucache_Serializer_Key, serializer);
|
||||
}
|
||||
_nuCacheContentService.RebuildDatabaseCacheIfSerializerChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user