BatchedDatabaseServerMessenger only exists in Web now, no reason for it to be in Core. CoreBootManager by default now uses DatabaseServerMessenger (non-batched), WebBootManager now uses BatchedDatabaseServerMessenger and is always enabled by default unless the Dist Calls setting in umbracoSettings is enabled, in that case it will revert to using the legacy batched web services messenger.
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
using umbraco.interfaces;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Rdbms;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -14,7 +18,7 @@ namespace Umbraco.Web
|
||||
/// <remarks>
|
||||
/// This binds to appropriate umbraco events in order to trigger the Boot(), Sync() & FlushBatch() calls
|
||||
/// </remarks>
|
||||
public class BatchedDatabaseServerMessenger : Core.Sync.BatchedDatabaseServerMessenger
|
||||
public class BatchedDatabaseServerMessenger : Core.Sync.DatabaseServerMessenger
|
||||
{
|
||||
public BatchedDatabaseServerMessenger(ApplicationContext appContext, bool enableDistCalls, DatabaseServerMessengerOptions options)
|
||||
: base(appContext, enableDistCalls, options)
|
||||
@@ -66,7 +70,37 @@ namespace Umbraco.Web
|
||||
FlushBatch();
|
||||
}
|
||||
|
||||
protected override ICollection<RefreshInstructionEnvelope> GetBatch(bool ensureHttpContext)
|
||||
protected override void DeliverRemote(IEnumerable<IServerAddress> servers, ICacheRefresher refresher, MessageType messageType, IEnumerable<object> ids = null, string json = null)
|
||||
{
|
||||
var idsA = ids == null ? null : ids.ToArray();
|
||||
|
||||
Type arrayType;
|
||||
if (GetArrayType(idsA, out arrayType) == false)
|
||||
throw new ArgumentException("All items must be of the same type, either int or Guid.", "ids");
|
||||
|
||||
BatchMessage(servers, refresher, messageType, idsA, arrayType, json);
|
||||
}
|
||||
|
||||
public void FlushBatch()
|
||||
{
|
||||
var batch = GetBatch(false);
|
||||
if (batch == null) return;
|
||||
|
||||
var instructions = batch.SelectMany(x => x.Instructions).ToArray();
|
||||
batch.Clear();
|
||||
if (instructions.Length == 0) return;
|
||||
|
||||
var dto = new CacheInstructionDto
|
||||
{
|
||||
UtcStamp = DateTime.UtcNow,
|
||||
Instructions = JsonConvert.SerializeObject(instructions, Formatting.None),
|
||||
OriginIdentity = LocalIdentity
|
||||
};
|
||||
|
||||
ApplicationContext.DatabaseContext.Database.Insert(dto);
|
||||
}
|
||||
|
||||
protected ICollection<RefreshInstructionEnvelope> GetBatch(bool ensureHttpContext)
|
||||
{
|
||||
var httpContext = UmbracoContext.Current == null ? null : UmbracoContext.Current.HttpContext;
|
||||
if (httpContext == null)
|
||||
@@ -84,5 +118,21 @@ namespace Umbraco.Web
|
||||
httpContext.Items[key] = batch = new List<RefreshInstructionEnvelope>();
|
||||
return batch;
|
||||
}
|
||||
|
||||
protected void BatchMessage(
|
||||
IEnumerable<IServerAddress> servers,
|
||||
ICacheRefresher refresher,
|
||||
MessageType messageType,
|
||||
IEnumerable<object> ids = null,
|
||||
Type idType = null,
|
||||
string json = null)
|
||||
{
|
||||
var batch = GetBatch(true);
|
||||
if (batch == null)
|
||||
throw new Exception("Failed to get a batch.");
|
||||
|
||||
batch.Add(new RefreshInstructionEnvelope(servers, refresher,
|
||||
RefreshInstruction.GetInstructions(refresher, messageType, ids, idType, json)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user