diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotServiceEventHandler.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotServiceEventHandler.cs index 81c9710ad6..e2f8f57bbe 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotServiceEventHandler.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotServiceEventHandler.cs @@ -1,12 +1,9 @@ using System; -using System.Collections.Generic; using System.Linq; -using Umbraco.Cms.Core; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.PublishedCache; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.Changes; using Umbraco.Cms.Infrastructure.PublishedCache.Persistence; using Umbraco.Extensions; @@ -17,7 +14,6 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache /// Subscribes to Umbraco events to ensure nucache remains consistent with the source data /// public class PublishedSnapshotServiceEventHandler : - IDisposable, INotificationHandler, INotificationHandler, INotificationHandler, @@ -28,47 +24,18 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache INotificationHandler, INotificationHandler { - private readonly IRuntimeState _runtime; - private bool _disposedValue; private readonly IPublishedSnapshotService _publishedSnapshotService; private readonly INuCacheContentService _publishedContentService; - private readonly IContentService _contentService; - private readonly IMediaService _mediaService; /// /// Initializes a new instance of the class. /// public PublishedSnapshotServiceEventHandler( - IRuntimeState runtime, IPublishedSnapshotService publishedSnapshotService, - INuCacheContentService publishedContentService, - IContentService contentService, - IMediaService mediaService) + INuCacheContentService publishedContentService) { - _runtime = runtime; _publishedSnapshotService = publishedSnapshotService; _publishedContentService = publishedContentService; - _contentService = contentService; - _mediaService = mediaService; - } - - /// - /// Binds to the Umbraco events - /// - /// Returns true if binding occurred - public bool Initialize() - { - // however, the cache is NOT available until we are configured, because loading - // content (and content types) from database cannot be consistent (see notes in "Handle - // Notifications" region), so - // - notifications will be ignored - // - trying to obtain a published snapshot from the service will throw - if (_runtime.Level != RuntimeLevel.Run) - { - return false; - } - - return true; } // note: if the service is not ready, ie _isReady is false, then we still handle repository events, @@ -136,20 +103,5 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache _publishedSnapshotService.Rebuild(contentTypeIds: Array.Empty()); } } - - protected virtual void Dispose(bool disposing) - { - if (!_disposedValue) - { - _disposedValue = true; - } - } - - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); - } } } diff --git a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs index 2b83d1e33a..9df64c64ad 100644 --- a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs +++ b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; @@ -20,7 +19,6 @@ using Umbraco.Cms.Core.Routing; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Web; -using Umbraco.Cms.Infrastructure.PublishedCache; using Umbraco.Cms.Infrastructure.WebAssets; using Umbraco.Cms.Web.Common.Profiler; using Umbraco.Extensions; @@ -45,7 +43,6 @@ namespace Umbraco.Cms.Web.Common.Middleware private readonly IUmbracoContextFactory _umbracoContextFactory; private readonly IRequestCache _requestCache; - private readonly PublishedSnapshotServiceEventHandler _publishedSnapshotServiceEventHandler; private readonly IEventAggregator _eventAggregator; private readonly IHostingEnvironment _hostingEnvironment; private readonly UmbracoRequestPaths _umbracoRequestPaths; @@ -56,10 +53,6 @@ namespace Umbraco.Cms.Web.Common.Middleware private SmidgeOptions _smidgeOptions; private readonly WebProfiler _profiler; - private static bool s_cacheInitialized; - private static bool s_cacheInitializedFlag = false; - private static object s_cacheInitializedLock = new object(); - #pragma warning disable IDE0044 // Add readonly modifier private static bool s_firstBackOfficeRequest; private static bool s_firstBackOfficeReqestFlag; @@ -73,7 +66,6 @@ namespace Umbraco.Cms.Web.Common.Middleware ILogger logger, IUmbracoContextFactory umbracoContextFactory, IRequestCache requestCache, - PublishedSnapshotServiceEventHandler publishedSnapshotServiceEventHandler, IEventAggregator eventAggregator, IProfiler profiler, IHostingEnvironment hostingEnvironment, @@ -87,7 +79,6 @@ namespace Umbraco.Cms.Web.Common.Middleware _logger = logger; _umbracoContextFactory = umbracoContextFactory; _requestCache = requestCache; - _publishedSnapshotServiceEventHandler = publishedSnapshotServiceEventHandler; _eventAggregator = eventAggregator; _hostingEnvironment = hostingEnvironment; _umbracoRequestPaths = umbracoRequestPaths; @@ -117,8 +108,6 @@ namespace Umbraco.Cms.Web.Common.Middleware // Also MiniProfiler.Current becomes null if it is handled by the event aggregator due to async/await _profiler?.UmbracoApplicationBeginRequest(context, _runtimeState.Level); - EnsureContentCacheInitialized(); - _variationContextAccessor.VariationContext ??= new VariationContext(_defaultCultureAccessor.DefaultCulture); UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext(); @@ -230,18 +219,5 @@ namespace Umbraco.Cms.Web.Common.Middleware IHttpScopeReference httpScopeReference = request.HttpContext.RequestServices.GetRequiredService(); httpScopeReference.Register(); } - - /// - /// Initializes the content cache one time - /// - private void EnsureContentCacheInitialized() => LazyInitializer.EnsureInitialized( - ref s_cacheInitialized, - ref s_cacheInitializedFlag, - ref s_cacheInitializedLock, - () => - { - _publishedSnapshotServiceEventHandler.Initialize(); - return true; - }); } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs index 04617ae5f3..7e22e22dd6 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs @@ -4,19 +4,16 @@ using System; using System.Linq; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; using NPoco; using NUnit.Framework; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.ContentEditing; using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Sync; using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.Dtos; -using Umbraco.Cms.Infrastructure.PublishedCache; using Umbraco.Cms.Tests.Common.Builders; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; @@ -40,14 +37,6 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services private ILocalizationService LocalizationService => GetRequiredService(); - protected override void BeforeHostStart(IHost host) - { - base.BeforeHostStart(host); - - // Ensure that the events are bound on each test - PublishedSnapshotServiceEventHandler eventBinder = host.Services.GetRequiredService(); - eventBinder.Initialize(); - } protected override void CustomTestSetup(IUmbracoBuilder builder) { @@ -57,8 +46,6 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services { options.NuCacheSerializerType = NuCacheSerializerType.JSON; }); - - } private void AssertJsonStartsWith(int id, string expected)