Merge pull request #9859 from nzdev/v8/bugfix/fix-cold-boot

Reduce cold boot times by loading content and media only once on cold boot
This commit is contained in:
Shannon Deminick
2021-04-26 15:52:41 +10:00
committed by GitHub
14 changed files with 180 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Sync;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
namespace Umbraco.Web.PublishedCache.NuCache
@@ -10,6 +11,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
base.Compose(composition);
//Overriden on Run state in DatabaseServerRegistrarAndMessengerComposer
composition.Register<ISyncBootStateAccessor, NonRuntimeLevelBootStateAccessor>(Lifetime.Singleton);
// register the NuCache database data source
composition.Register<IDataSource, DatabaseDataSource>();

View File

@@ -24,6 +24,7 @@ using Umbraco.Core.Services;
using Umbraco.Core.Services.Changes;
using Umbraco.Core.Services.Implement;
using Umbraco.Core.Strings;
using Umbraco.Core.Sync;
using Umbraco.Web.Cache;
using Umbraco.Web.Install;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
@@ -63,6 +64,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
private bool _localContentDbExists;
private bool _localMediaDbExists;
private readonly ISyncBootStateAccessor _syncBootStateAccessor;
// define constant - determines whether to use cache when previewing
// to store eg routes, property converted values, anything - caching
// means faster execution, but uses memory - not sure if we want it
@@ -81,7 +84,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
IDataSource dataSource, IGlobalSettings globalSettings,
IEntityXmlSerializer entitySerializer,
IPublishedModelFactory publishedModelFactory,
UrlSegmentProviderCollection urlSegmentProviders)
UrlSegmentProviderCollection urlSegmentProviders,
ISyncBootStateAccessor syncBootStateAccessor)
: base(publishedSnapshotAccessor, variationContextAccessor)
{
//if (Interlocked.Increment(ref _singletonCheck) > 1)
@@ -99,6 +103,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
_globalSettings = globalSettings;
_urlSegmentProviders = urlSegmentProviders;
_syncBootStateAccessor = syncBootStateAccessor;
// we need an Xml serializer here so that the member cache can support XPath,
// for members this is done by navigating the serialized-to-xml member
_entitySerializer = entitySerializer;
@@ -217,7 +223,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
var okContent = false;
var okMedia = false;
if (_syncBootStateAccessor.GetSyncBootState() == SyncBootState.ColdBoot)
{
_logger.Info<PublishedSnapshotService>("Sync Service is in a Cold Boot state. Skip LoadCachesOnStartup as the Sync Service will trigger a full reload");
_isReady = true;
return;
}
try
{
if (_localContentDbExists)
@@ -233,7 +244,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (!okMedia)
_logger.Warn<PublishedSnapshotService>("Loading media from local db raised warnings, will reload from database.");
}
if (!okContent)
LockAndLoadContent(scope => LoadContentFromDatabaseLocked(scope, true));