diff --git a/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs b/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs
index 0810f2207b..39b9f038be 100644
--- a/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs
+++ b/src/Umbraco.Core/Models/PublishedContent/ILivePublishedModelFactory.cs
@@ -1,5 +1,21 @@
namespace Umbraco.Core.Models.PublishedContent
{
+ ///
+ /// Provides a live published model creation service.
+ ///
+ public interface ILivePublishedModelFactory2 : ILivePublishedModelFactory
+ {
+ ///
+ /// Tells the factory that it should build a new generation of models
+ ///
+ void Reset();
+
+ ///
+ /// If the live model factory
+ ///
+ bool Enabled { get; }
+ }
+
///
/// Provides a live published model creation service.
///
diff --git a/src/Umbraco.Core/PublishedModelFactoryExtensions.cs b/src/Umbraco.Core/PublishedModelFactoryExtensions.cs
index ac8c9f1be7..697e3fd11f 100644
--- a/src/Umbraco.Core/PublishedModelFactoryExtensions.cs
+++ b/src/Umbraco.Core/PublishedModelFactoryExtensions.cs
@@ -17,6 +17,20 @@ namespace Umbraco.Core
///
public static bool IsLiveFactory(this IPublishedModelFactory factory) => factory is ILivePublishedModelFactory;
+ ///
+ /// Returns true if the current is an implementation of and is enabled
+ ///
+ ///
+ ///
+ public static bool IsLiveFactoryEnabled(this IPublishedModelFactory factory)
+ {
+ if (factory is ILivePublishedModelFactory2 liveFactory2)
+ return liveFactory2.Enabled;
+
+ // if it's not ILivePublishedModelFactory2 we can't determine if it's enabled or not so return true
+ return factory is ILivePublishedModelFactory;
+ }
+
[Obsolete("This method is no longer used or necessary and will be removed from future")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void WithSafeLiveFactory(this IPublishedModelFactory factory, Action action)
@@ -50,15 +64,17 @@ namespace Umbraco.Core
{
lock (liveFactory.SyncRoot)
{
- // TODO: Fix this in 8.3! - We need to change the ILivePublishedModelFactory interface to have a Reset method and then when we have an embedded MB
- // version we will publicize the ResetModels (and change the name to Reset).
- // For now, this will suffice and we'll use reflection, there should be no other implementation of ILivePublishedModelFactory.
- // Calling ResetModels resets the MB flag so that the next time EnsureModels is called (which is called when nucache lazily calls CreateModel) it will
- // trigger the recompiling of pure live models.
- var resetMethod = liveFactory.GetType().GetMethod("ResetModels", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
- if (resetMethod != null)
- resetMethod.Invoke(liveFactory, null);
-
+ if (liveFactory is ILivePublishedModelFactory2 liveFactory2)
+ {
+ liveFactory2.Reset();
+ }
+ else
+ {
+ // This is purely here for backwards compat and to avoid breaking changes but this code will probably never get executed
+ var resetMethod = liveFactory.GetType().GetMethod("ResetModels", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
+ if (resetMethod != null)
+ resetMethod.Invoke(liveFactory, null);
+ }
action();
}
}
diff --git a/src/Umbraco.Core/Runtime/SqlMainDomLock.cs b/src/Umbraco.Core/Runtime/SqlMainDomLock.cs
index f3bfe4eefc..5f5d0d607f 100644
--- a/src/Umbraco.Core/Runtime/SqlMainDomLock.cs
+++ b/src/Umbraco.Core/Runtime/SqlMainDomLock.cs
@@ -3,8 +3,10 @@ using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
+using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
+using System.Web;
using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.Dtos;
@@ -16,7 +18,7 @@ namespace Umbraco.Core.Runtime
internal class SqlMainDomLock : IMainDomLock
{
private string _lockId;
- private const string MainDomKey = "Umbraco.Core.Runtime.SqlMainDom";
+ private const string MainDomKeyPrefix = "Umbraco.Core.Runtime.SqlMainDom";
private const string UpdatedSuffix = "_updated";
private readonly ILogger _logger;
private IUmbracoDatabase _db;
@@ -126,6 +128,16 @@ namespace Umbraco.Core.Runtime
}
+ ///
+ /// Returns the keyvalue table key for the current server/app
+ ///
+ ///
+ /// The key is the the normal MainDomId which takes into account the AppDomainAppId and the physical file path of the app and this is
+ /// combined with the current machine name. The machine name is required because the default semaphore lock is machine wide so it implicitly
+ /// takes into account machine name whereas this needs to be explicitly per machine.
+ ///
+ private string MainDomKey { get; } = MainDomKeyPrefix + "-" + (NetworkHelper.MachineName + MainDom.GetMainDomId()).GenerateHash();
+
private void ListeningLoop()
{
while (true)
diff --git a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs
index 8e8a19c729..0e125759c6 100644
--- a/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs
+++ b/src/Umbraco.ModelsBuilder.Embedded/PureLiveModelFactory.cs
@@ -21,7 +21,7 @@ using File = System.IO.File;
namespace Umbraco.ModelsBuilder.Embedded
{
- internal class PureLiveModelFactory : ILivePublishedModelFactory, IRegisteredObject
+ internal class PureLiveModelFactory : ILivePublishedModelFactory2, IRegisteredObject
{
private Assembly _modelsAssembly;
private Infos _infos = new Infos { ModelInfos = null, ModelTypeMap = new Dictionary() };
@@ -134,6 +134,16 @@ namespace Umbraco.ModelsBuilder.Embedded
return ctor();
}
+ ///
+ public bool Enabled => _config.Enable;
+
+ ///
+ public void Reset()
+ {
+ if (_config.Enable)
+ ResetModels();
+ }
+
#endregion
#region Compilation
diff --git a/src/Umbraco.Web/Editors/ExamineManagementController.cs b/src/Umbraco.Web/Editors/ExamineManagementController.cs
index 0953b41cac..cf1dfd5d5d 100644
--- a/src/Umbraco.Web/Editors/ExamineManagementController.cs
+++ b/src/Umbraco.Web/Editors/ExamineManagementController.cs
@@ -141,9 +141,6 @@ namespace Umbraco.Web.Editors
try
{
- //clear and replace
- index.CreateIndex();
-
var cacheKey = "temp_indexing_op_" + index.Name;
//put temp val in cache which is used as a rudimentary way to know when the indexing is done
AppCaches.RuntimeCache.Insert(cacheKey, () => "tempValue", TimeSpan.FromMinutes(5));
diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs
index 6866878484..7e78b2e96f 100755
--- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs
+++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs
@@ -859,7 +859,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
Notify(_contentStore, payloads, RefreshContentTypesLocked);
Notify(_mediaStore, payloads, RefreshMediaTypesLocked);
- if (_publishedModelFactory.IsLiveFactory())
+ if (_publishedModelFactory.IsLiveFactoryEnabled())
{
//In the case of Pure Live - we actually need to refresh all of the content and the media
//see https://github.com/umbraco/Umbraco-CMS/issues/5671
diff --git a/src/Umbraco.Web/PublishedCache/PublishedSnapshotServiceBase.cs b/src/Umbraco.Web/PublishedCache/PublishedSnapshotServiceBase.cs
index 20d3e6d8e3..1b56f54569 100644
--- a/src/Umbraco.Web/PublishedCache/PublishedSnapshotServiceBase.cs
+++ b/src/Umbraco.Web/PublishedCache/PublishedSnapshotServiceBase.cs
@@ -1,11 +1,12 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Cache;
namespace Umbraco.Web.PublishedCache
{
- abstract class PublishedSnapshotServiceBase : IPublishedSnapshotService
+ internal abstract class PublishedSnapshotServiceBase : IPublishedSnapshotService
{
protected PublishedSnapshotServiceBase(IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
{