Add work on PublishedSnapshotService
This commit is contained in:
@@ -39,9 +39,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
{
|
||||
private readonly ServiceContext _serviceContext;
|
||||
private readonly IPublishedContentTypeFactory _publishedContentTypeFactory;
|
||||
private readonly IProfilingLogger _profilingLogger;
|
||||
private readonly IScopeProvider _scopeProvider;
|
||||
private readonly IDataSource _dataSource;
|
||||
private readonly IProfilingLogger _logger;
|
||||
private readonly ILogger<PublishedSnapshotService> _logger;
|
||||
private readonly ILogger<PublishedContentTypeCache> _publishedContentTypeCacheLogger;
|
||||
private readonly IDocumentRepository _documentRepository;
|
||||
private readonly IMediaRepository _mediaRepository;
|
||||
private readonly IMemberRepository _memberRepository;
|
||||
@@ -81,7 +83,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
public PublishedSnapshotService(PublishedSnapshotServiceOptions options, IMainDom mainDom, IRuntimeState runtime,
|
||||
ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IProfilingLogger logger, IScopeProvider scopeProvider,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
|
||||
IProfilingLogger profilingLogger, ILogger<PublishedSnapshotService> logger, ILogger<ContentStore> contentLogger, ILogger<ContentStore.Snapshot> snapshotLogger, ILogger<PublishedContentTypeCache> publishedContentTypeCacheLogger,
|
||||
IScopeProvider scopeProvider,
|
||||
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
|
||||
IDefaultCultureAccessor defaultCultureAccessor,
|
||||
IDataSource dataSource, IGlobalSettings globalSettings,
|
||||
@@ -99,8 +103,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
_serviceContext = serviceContext;
|
||||
_publishedContentTypeFactory = publishedContentTypeFactory;
|
||||
_profilingLogger = profilingLogger;
|
||||
_dataSource = dataSource;
|
||||
_logger = logger;
|
||||
_publishedContentTypeCacheLogger = publishedContentTypeCacheLogger;
|
||||
_scopeProvider = scopeProvider;
|
||||
_documentRepository = documentRepository;
|
||||
_mediaRepository = mediaRepository;
|
||||
@@ -144,18 +150,18 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// stores are created with a db so they can write to it, but they do not read from it,
|
||||
// stores need to be populated, happens in OnResolutionFrozen which uses _localDbExists to
|
||||
// figure out whether it can read the databases or it should populate them from sql
|
||||
|
||||
_logger.Info<PublishedSnapshotService>("Creating the content store, localContentDbExists? {LocalContentDbExists}", _localContentDbExists);
|
||||
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger, publishedModelFactory, _localContentDb);
|
||||
_logger.Info<PublishedSnapshotService>("Creating the media store, localMediaDbExists? {LocalMediaDbExists}", _localMediaDbExists);
|
||||
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger, publishedModelFactory, _localMediaDb);
|
||||
|
||||
_logger.LogInformation("Creating the content store, localContentDbExists? {LocalContentDbExists}", _localContentDbExists);
|
||||
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, contentLogger, snapshotLogger, publishedModelFactory, _localContentDb);
|
||||
_logger.LogInformation("Creating the media store, localMediaDbExists? {LocalMediaDbExists}", _localMediaDbExists);
|
||||
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, contentLogger, snapshotLogger, publishedModelFactory, _localMediaDb);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Info<PublishedSnapshotService>("Creating the content store (local db ignored)");
|
||||
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger, publishedModelFactory);
|
||||
_logger.Info<PublishedSnapshotService>("Creating the media store (local db ignored)");
|
||||
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger, publishedModelFactory);
|
||||
_logger.LogInformation("Creating the content store (local db ignored)");
|
||||
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, contentLogger, snapshotLogger, publishedModelFactory);
|
||||
_logger.LogInformation("Creating the media store (local db ignored)");
|
||||
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, contentLogger, snapshotLogger, publishedModelFactory);
|
||||
}
|
||||
|
||||
_domainStore = new SnapDictionary<int, Domain>();
|
||||
@@ -201,7 +207,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
_localContentDb = BTree.GetTree(localContentDbPath, _localContentDbExists, _config);
|
||||
_localMediaDb = BTree.GetTree(localMediaDbPath, _localMediaDbExists, _config);
|
||||
|
||||
_logger.Info<PublishedSnapshotService>("Registered with MainDom, localContentDbExists? {LocalContentDbExists}, localMediaDbExists? {LocalMediaDbExists}", _localContentDbExists, _localMediaDbExists);
|
||||
_logger.LogInformation("Registered with MainDom, localContentDbExists? {LocalContentDbExists}, localMediaDbExists? {LocalMediaDbExists}", _localContentDbExists, _localMediaDbExists);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -212,19 +218,19 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
/// </remarks>
|
||||
private void MainDomRelease()
|
||||
{
|
||||
_logger.Debug<PublishedSnapshotService>("Releasing from MainDom...");
|
||||
_logger.LogDebug("Releasing from MainDom...");
|
||||
|
||||
lock (_storesLock)
|
||||
{
|
||||
_logger.Debug<PublishedSnapshotService>("Releasing content store...");
|
||||
_logger.LogDebug("Releasing content store...");
|
||||
_contentStore?.ReleaseLocalDb(); //null check because we could shut down before being assigned
|
||||
_localContentDb = null;
|
||||
|
||||
_logger.Debug<PublishedSnapshotService>("Releasing media store...");
|
||||
_logger.LogDebug("Releasing media store...");
|
||||
_mediaStore?.ReleaseLocalDb(); //null check because we could shut down before being assigned
|
||||
_localMediaDb = null;
|
||||
|
||||
_logger.Info<PublishedSnapshotService>("Released from MainDom");
|
||||
_logger.LogInformation("Released from MainDom");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,14 +249,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
{
|
||||
okContent = LockAndLoadContent(scope => LoadContentFromLocalDbLocked(true));
|
||||
if (!okContent)
|
||||
_logger.LogWarning<PublishedSnapshotService>("Loading content from local db raised warnings, will reload from database.");
|
||||
_logger.LogWarning("Loading content from local db raised warnings, will reload from database.");
|
||||
}
|
||||
|
||||
if (_localMediaDbExists)
|
||||
{
|
||||
okMedia = LockAndLoadMedia(scope => LoadMediaFromLocalDbLocked(true));
|
||||
if (!okMedia)
|
||||
_logger.LogWarning<PublishedSnapshotService>("Loading media from local db raised warnings, will reload from database.");
|
||||
_logger.LogWarning("Loading media from local db raised warnings, will reload from database.");
|
||||
}
|
||||
|
||||
if (!okContent)
|
||||
@@ -263,7 +269,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Fatal<PublishedSnapshotService>(ex, "Panic, exception while loading cache data.");
|
||||
_logger.LogCritical(ex, "Panic, exception while loading cache data.");
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -406,7 +412,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
_contentStore.SetAllContentTypesLocked(contentTypes);
|
||||
|
||||
using (_logger.TraceDuration<PublishedSnapshotService>("Loading content from database"))
|
||||
using (_profilingLogger.TraceDuration<PublishedSnapshotService>("Loading content from database"))
|
||||
{
|
||||
// beware! at that point the cache is inconsistent,
|
||||
// assuming we are going to SetAll content items!
|
||||
@@ -425,7 +431,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
.Select(x => _publishedContentTypeFactory.CreateContentType(x));
|
||||
_contentStore.SetAllContentTypesLocked(contentTypes);
|
||||
|
||||
using (_logger.TraceDuration<PublishedSnapshotService>("Loading content from local cache file"))
|
||||
using (_profilingLogger.TraceDuration<PublishedSnapshotService>("Loading content from local cache file"))
|
||||
{
|
||||
// beware! at that point the cache is inconsistent,
|
||||
// assuming we are going to SetAll content items!
|
||||
@@ -477,14 +483,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
.Select(x => _publishedContentTypeFactory.CreateContentType(x));
|
||||
_mediaStore.SetAllContentTypesLocked(mediaTypes);
|
||||
|
||||
using (_logger.TraceDuration<PublishedSnapshotService>("Loading media from database"))
|
||||
using (_profilingLogger.TraceDuration<PublishedSnapshotService>("Loading media from database"))
|
||||
{
|
||||
// beware! at that point the cache is inconsistent,
|
||||
// assuming we are going to SetAll content items!
|
||||
|
||||
_localMediaDb?.Clear();
|
||||
|
||||
_logger.Debug<PublishedSnapshotService>("Loading media from database...");
|
||||
_logger.LogDebug("Loading media from database...");
|
||||
// IMPORTANT GetAllMediaSources sorts kits by level + parentId + sortOrder
|
||||
var kits = _dataSource.GetAllMediaSources(scope);
|
||||
return onStartup ? _mediaStore.SetAllFastSortedLocked(kits, true) : _mediaStore.SetAllLocked(kits);
|
||||
@@ -497,7 +503,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
.Select(x => _publishedContentTypeFactory.CreateContentType(x));
|
||||
_mediaStore.SetAllContentTypesLocked(mediaTypes);
|
||||
|
||||
using (_logger.TraceDuration<PublishedSnapshotService>("Loading media from local cache file"))
|
||||
using (_profilingLogger.TraceDuration<PublishedSnapshotService>("Loading media from local cache file"))
|
||||
{
|
||||
// beware! at that point the cache is inconsistent,
|
||||
// assuming we are going to SetAll content items!
|
||||
@@ -532,7 +538,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
// Update: We will still return false here even though the above mentioned race condition has been fixed since we now
|
||||
// lock the entire operation of creating/populating the cache file with the same lock as releasing/closing the cache file
|
||||
|
||||
_logger.Info<PublishedSnapshotService>($"Tried to load {entityType} from the local cache file but it was empty.");
|
||||
_logger.LogInformation($"Tried to load {entityType} from the local cache file but it was empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -709,7 +715,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
foreach (var payload in payloads)
|
||||
{
|
||||
_logger.Debug<PublishedSnapshotService>("Notified {ChangeTypes} for content {ContentId}", payload.ChangeTypes, payload.Id);
|
||||
_logger.LogDebug("Notified {ChangeTypes} for content {ContentId}", payload.ChangeTypes, payload.Id);
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
|
||||
{
|
||||
@@ -802,7 +808,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
foreach (var payload in payloads)
|
||||
{
|
||||
_logger.Debug<PublishedSnapshotService>("Notified {ChangeTypes} for media {MediaId}", payload.ChangeTypes, payload.Id);
|
||||
_logger.LogDebug("Notified {ChangeTypes} for media {MediaId}", payload.ChangeTypes, payload.Id);
|
||||
|
||||
if (payload.ChangeTypes.HasType(TreeChangeTypes.RefreshAll))
|
||||
{
|
||||
@@ -873,7 +879,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
return;
|
||||
|
||||
foreach (var payload in payloads)
|
||||
_logger.Debug<PublishedSnapshotService>("Notified {ChangeTypes} for {ItemType} {ItemId}", payload.ChangeTypes, payload.ItemType, payload.Id);
|
||||
_logger.LogDebug("Notified {ChangeTypes} for {ItemType} {ItemId}", payload.ChangeTypes, payload.ItemType, payload.Id);
|
||||
|
||||
Notify<IContentType>(_contentStore, payloads, RefreshContentTypesLocked);
|
||||
Notify<IMediaType>(_mediaStore, payloads, RefreshMediaTypesLocked);
|
||||
@@ -957,7 +963,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
var idsA = payloads.Select(x => x.Id).ToArray();
|
||||
|
||||
foreach (var payload in payloads)
|
||||
_logger.Debug<PublishedSnapshotService>("Notified {RemovedStatus} for data type {DataTypeId}",
|
||||
_logger.LogDebug("Notified {RemovedStatus} for data type {DataTypeId}",
|
||||
payload.Removed ? "Removed" : "Refreshed",
|
||||
payload.Id);
|
||||
|
||||
@@ -1229,7 +1235,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
var snapshotCache = new DictionaryAppCache();
|
||||
|
||||
var memberTypeCache = new PublishedContentTypeCache(null, null, _serviceContext.MemberTypeService, _publishedContentTypeFactory, _logger);
|
||||
var memberTypeCache = new PublishedContentTypeCache(null, null, _serviceContext.MemberTypeService, _publishedContentTypeFactory, _publishedContentTypeCacheLogger);
|
||||
|
||||
var defaultCulture = _defaultCultureAccessor.DefaultCulture;
|
||||
var domainCache = new DomainCache(domainSnap, defaultCulture);
|
||||
@@ -1490,7 +1496,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
public override void Rebuild()
|
||||
{
|
||||
_logger.Debug<PublishedSnapshotService>("Rebuilding...");
|
||||
_logger.LogDebug("Rebuilding...");
|
||||
using (var scope = _scopeProvider.CreateScope(repositoryCacheMode: RepositoryCacheMode.Scoped))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
|
||||
Reference in New Issue
Block a user