From baacedd57d1db616ea429d5f90f0f9859eab4de0 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Fri, 19 Mar 2021 08:09:00 +0100 Subject: [PATCH] Fixed bug where indexes was build before application was in run state + Moved the logic to the application started event --- .../Search/ExamineFinalComponent.cs | 33 ------------------- .../Search/ExamineFinalComposer.cs | 11 ------- .../Search/ExamineNotificationHandler.cs | 10 ++++-- 3 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs delete mode 100644 src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs diff --git a/src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs b/src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs deleted file mode 100644 index 441d8af038..0000000000 --- a/src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using Umbraco.Cms.Core.Composing; -using Umbraco.Cms.Core.Runtime; - -namespace Umbraco.Cms.Infrastructure.Search -{ - /// - /// Executes after all other examine components have executed - /// - public sealed class ExamineFinalComponent : IComponent - { - BackgroundIndexRebuilder _indexRebuilder; - private readonly IMainDom _mainDom; - - public ExamineFinalComponent(BackgroundIndexRebuilder indexRebuilder, IMainDom mainDom) - { - _indexRebuilder = indexRebuilder; - _mainDom = mainDom; - } - - public void Initialize() - { - if (!_mainDom.IsMainDom) return; - - // TODO: Instead of waiting 5000 ms, we could add an event handler on to fulfilling the first request, then start? - _indexRebuilder.RebuildIndexes(true, TimeSpan.FromSeconds(5)); - } - - public void Terminate() - { - } - } -} diff --git a/src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs b/src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs deleted file mode 100644 index 037a3d1622..0000000000 --- a/src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Umbraco.Cms.Core.Composing; - -namespace Umbraco.Cms.Infrastructure.Search -{ - // examine's final composer composes after all user composers - // and *also* after ICoreComposer (in case IUserComposer is disabled) - [ComposeAfter(typeof(IUserComposer))] - [ComposeAfter(typeof(ICoreComposer))] - public class ExamineFinalComposer : ComponentComposer - { } -} diff --git a/src/Umbraco.Infrastructure/Search/ExamineNotificationHandler.cs b/src/Umbraco.Infrastructure/Search/ExamineNotificationHandler.cs index b10bf70c10..d22acb87e2 100644 --- a/src/Umbraco.Infrastructure/Search/ExamineNotificationHandler.cs +++ b/src/Umbraco.Infrastructure/Search/ExamineNotificationHandler.cs @@ -35,6 +35,7 @@ namespace Umbraco.Cms.Infrastructure.Search private readonly IValueSetBuilder _memberValueSetBuilder; private readonly BackgroundIndexRebuilder _backgroundIndexRebuilder; private readonly TaskHelper _taskHelper; + private readonly IRuntimeState _runtimeState; private readonly IScopeProvider _scopeProvider; private readonly ServiceContext _services; private readonly IMainDom _mainDom; @@ -60,7 +61,8 @@ namespace Umbraco.Cms.Infrastructure.Search IValueSetBuilder mediaValueSetBuilder, IValueSetBuilder memberValueSetBuilder, BackgroundIndexRebuilder backgroundIndexRebuilder, - TaskHelper taskHelper) + TaskHelper taskHelper, + IRuntimeState runtimeState) { _services = services; _scopeProvider = scopeProvider; @@ -71,6 +73,7 @@ namespace Umbraco.Cms.Infrastructure.Search _memberValueSetBuilder = memberValueSetBuilder; _backgroundIndexRebuilder = backgroundIndexRebuilder; _taskHelper = taskHelper; + _runtimeState = runtimeState; _mainDom = mainDom; _profilingLogger = profilingLogger; _logger = logger; @@ -114,7 +117,10 @@ namespace Umbraco.Cms.Infrastructure.Search s_deactivate_handlers = true; } - + if (_mainDom.IsMainDom && _runtimeState.Level >= RuntimeLevel.Run) + { + _backgroundIndexRebuilder.RebuildIndexes(true); + } }