From f60b91110f76f808ebaf008879ea752d379f716c Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 14 Aug 2019 10:56:08 +1000 Subject: [PATCH] Fixes merge --- src/Umbraco.Examine/ExamineExtensions.cs | 33 +++++++++---------- .../Search/BackgroundIndexRebuilder.cs | 2 +- .../Search/ExamineFinalComponent.cs | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Examine/ExamineExtensions.cs b/src/Umbraco.Examine/ExamineExtensions.cs index 0e451b298c..d231a86f69 100644 --- a/src/Umbraco.Examine/ExamineExtensions.cs +++ b/src/Umbraco.Examine/ExamineExtensions.cs @@ -12,6 +12,7 @@ using Lucene.Net.Store; using Umbraco.Core; using Version = Lucene.Net.Util.Version; using Umbraco.Core.Logging; +using System.Threading; namespace Umbraco.Examine { @@ -28,29 +29,27 @@ namespace Umbraco.Examine /// internal static readonly Regex CultureIsoCodeFieldNameMatchExpression = new Regex("^([_\\w]+)_([a-z]{2}-[a-z0-9]{2,4})$", RegexOptions.Compiled); - private static volatile bool _isUnlocked = false; - private static readonly object IsUnlockedLocker = new object(); + private static bool _isConfigured = false; + private static object _configuredInit = null; + private static object _isConfiguredLocker = new object(); /// - /// Unlocks all Lucene based indexes registered with the + /// Called on startup to configure each index. /// /// - /// Indexing rebuilding can occur on a normal boot if the indexes are empty or on a cold boot by the database server messenger. Before - /// either of these happens, we need to configure the indexes. + /// Configures and unlocks all Lucene based indexes registered with the . /// - internal static void EnsureUnlocked(this IExamineManager examineManager, IMainDom mainDom, ILogger logger) + internal static void ConfigureIndexes(this IExamineManager examineManager, IMainDom mainDom, ILogger logger) { - if (!mainDom.IsMainDom) return; - if (_isUnlocked) return; - - lock (IsUnlockedLocker) - { - //double check - if (_isUnlocked) return; - - _isUnlocked = true; - examineManager.UnlockLuceneIndexes(logger); - } + LazyInitializer.EnsureInitialized( + ref _configuredInit, + ref _isConfigured, + ref _isConfiguredLocker, + () => + { + examineManager.ConfigureLuceneIndexes(logger, !mainDom.IsMainDom); + return null; + }); } //TODO: We need a public method here to just match a field name against CultureIsoCodeFieldNameMatchExpression diff --git a/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs b/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs index d747d8d9e4..0ae5ceade9 100644 --- a/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs +++ b/src/Umbraco.Web/Search/BackgroundIndexRebuilder.cs @@ -115,7 +115,7 @@ namespace Umbraco.Web.Search if (_waitMilliseconds > 0) Thread.Sleep(_waitMilliseconds); - _indexRebuilder.ExamineManager.EnsureUnlocked(_mainDom, _logger); + _indexRebuilder.ExamineManager.ConfigureIndexes(_mainDom, _logger); _indexRebuilder.RebuildIndexes(_onlyEmptyIndexes); } } diff --git a/src/Umbraco.Web/Search/ExamineFinalComponent.cs b/src/Umbraco.Web/Search/ExamineFinalComponent.cs index 4514a78faa..95000b2b46 100644 --- a/src/Umbraco.Web/Search/ExamineFinalComponent.cs +++ b/src/Umbraco.Web/Search/ExamineFinalComponent.cs @@ -29,7 +29,7 @@ namespace Umbraco.Web.Search { if (!_mainDom.IsMainDom) return; - _examineManager.EnsureUnlocked(_mainDom, _logger); + _examineManager.ConfigureIndexes(_mainDom, _logger); // TODO: Instead of waiting 5000 ms, we could add an event handler on to fulfilling the first request, then start? _indexRebuilder.RebuildIndexes(true, 5000);