removes PublishedSnapshotServiceBase, shrinks interface

This commit is contained in:
Shannon
2020-12-21 17:04:29 +11:00
parent 03f22e9362
commit e8f5aa8ebc
4 changed files with 68 additions and 129 deletions

View File

@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Cache;
namespace Umbraco.Web.PublishedCache
@@ -23,11 +22,6 @@ namespace Umbraco.Web.PublishedCache
*
*/
/// <summary>
/// Gets the published snapshot accessor.
/// </summary>
IPublishedSnapshotAccessor PublishedSnapshotAccessor { get; }
/// <summary>
/// Creates a published snapshot.
/// </summary>

View File

@@ -1,78 +0,0 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Cache;
namespace Umbraco.Web.PublishedCache
{
// TODO: This base class probably shouldn't exist
public abstract class PublishedSnapshotServiceBase : IPublishedSnapshotService
{
/// <summary>
/// Initializes a new instance of the <see cref="PublishedSnapshotServiceBase"/> class.
/// </summary>
protected PublishedSnapshotServiceBase(IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
{
PublishedSnapshotAccessor = publishedSnapshotAccessor;
VariationContextAccessor = variationContextAccessor;
}
/// <inheritdoc/>
public IPublishedSnapshotAccessor PublishedSnapshotAccessor { get; }
/// <summary>
/// Gets the <see cref="IVariationContextAccessor"/>
/// </summary>
public IVariationContextAccessor VariationContextAccessor { get; }
// note: NOT setting _publishedSnapshotAccessor.PublishedSnapshot here because it is the
// responsibility of the caller to manage what the 'current' facade is
/// <inheritdoc/>
public abstract IPublishedSnapshot CreatePublishedSnapshot(string previewToken);
protected IPublishedSnapshot CurrentPublishedSnapshot => PublishedSnapshotAccessor.PublishedSnapshot;
/// <inheritdoc/>
public abstract bool EnsureEnvironment(out IEnumerable<string> errors);
/// <inheritdoc/>
public abstract void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged);
/// <inheritdoc/>
public abstract void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged);
/// <inheritdoc/>
public abstract void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads);
/// <inheritdoc/>
public abstract void Notify(DataTypeCacheRefresher.JsonPayload[] payloads);
/// <inheritdoc/>
public abstract void Notify(DomainCacheRefresher.JsonPayload[] payloads);
/// <inheritdoc/>
public abstract void Rebuild(
int groupSize = 5000,
IReadOnlyCollection<int> contentTypeIds = null,
IReadOnlyCollection<int> mediaTypeIds = null,
IReadOnlyCollection<int> memberTypeIds = null);
/// <inheritdoc/>
public virtual void Dispose()
{ }
/// <inheritdoc/>
public abstract string GetStatus();
/// <inheritdoc/>
public virtual string StatusUrl => "views/dashboard/settings/publishedsnapshotcache.html";
/// <inheritdoc/>
public virtual void Collect()
{
}
}
}

View File

@@ -14,7 +14,6 @@ using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.Scoping;
@@ -29,10 +28,12 @@ using File = System.IO.File;
namespace Umbraco.Web.PublishedCache.NuCache
{
internal class PublishedSnapshotService : PublishedSnapshotServiceBase
internal class PublishedSnapshotService : IPublishedSnapshotService
{
private readonly ServiceContext _serviceContext;
private readonly IPublishedContentTypeFactory _publishedContentTypeFactory;
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IProfilingLogger _profilingLogger;
private readonly IScopeProvider _scopeProvider;
private readonly INuCacheContentService _publishedContentService;
@@ -91,10 +92,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
IHostingEnvironment hostingEnvironment,
IIOHelper ioHelper, // TODO: Remove this, it is only needed for "EnsureEnvironment" which doesn't need to belong to this service
IOptions<NuCacheSettings> config)
: base(publishedSnapshotAccessor, variationContextAccessor)
{
_serviceContext = serviceContext;
_publishedContentTypeFactory = publishedContentTypeFactory;
_publishedSnapshotAccessor = publishedSnapshotAccessor;
_variationContextAccessor = variationContextAccessor;
_profilingLogger = profilingLogger;
_loggerFactory = loggerFactory;
_logger = _loggerFactory.CreateLogger<PublishedSnapshotService>();
@@ -126,22 +128,24 @@ namespace Umbraco.Web.PublishedCache.NuCache
// figure out whether it can read the databases or it should populate them from sql
_logger.LogInformation("Creating the content store, localContentDbExists? {LocalContentDbExists}", _localContentDbExists);
_contentStore = new ContentStore(PublishedSnapshotAccessor, VariationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localContentDb);
_contentStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localContentDb);
_logger.LogInformation("Creating the media store, localMediaDbExists? {LocalMediaDbExists}", _localMediaDbExists);
_mediaStore = new ContentStore(PublishedSnapshotAccessor, VariationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localMediaDb);
_mediaStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory, _localMediaDb);
}
else
{
_logger.LogInformation("Creating the content store (local db ignored)");
_contentStore = new ContentStore(PublishedSnapshotAccessor, VariationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory);
_contentStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory);
_logger.LogInformation("Creating the media store (local db ignored)");
_mediaStore = new ContentStore(PublishedSnapshotAccessor, VariationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory);
_mediaStore = new ContentStore(_publishedSnapshotAccessor, _variationContextAccessor, _loggerFactory.CreateLogger("ContentStore"), _loggerFactory, _publishedModelFactory);
}
_domainStore = new SnapDictionary<int, Domain>();
}
}
protected PublishedSnapshot CurrentPublishedSnapshot => (PublishedSnapshot)_publishedSnapshotAccessor.PublishedSnapshot;
// NOTE: These aren't used within this object but are made available internally to improve the IdKey lookup performance
// when nucache is enabled.
// TODO: Does this need to be here?
@@ -249,7 +253,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
public override bool EnsureEnvironment(out IEnumerable<string> errors)
public bool EnsureEnvironment(out IEnumerable<string> errors)
{
// must have app_data and be able to write files into it
var ok = _ioHelper.TryCreateDirectory(GetLocalFilesPath());
@@ -497,7 +501,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// pure live model factory, if any, locked and refreshed - see ContentTypeCacheRefresher and
// DataTypeCacheRefresher
public override void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged)
public void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged)
{
// no cache, trash everything
if (Volatile.Read(ref _isReady) == false)
@@ -516,7 +520,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (draftChanged || publishedChanged)
{
((PublishedSnapshot)CurrentPublishedSnapshot)?.Resync();
CurrentPublishedSnapshot.Resync();
}
}
@@ -598,7 +602,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
/// <inheritdoc />
public override void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged)
public void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged)
{
// no cache, trash everything
if (Volatile.Read(ref _isReady) == false)
@@ -616,7 +620,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (anythingChanged)
{
((PublishedSnapshot)CurrentPublishedSnapshot)?.Resync();
CurrentPublishedSnapshot.Resync();
}
}
@@ -696,7 +700,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
/// <inheritdoc />
public override void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads)
public void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads)
{
// no cache, nothing we can do
if (Volatile.Read(ref _isReady) == false)
@@ -746,7 +750,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
((PublishedSnapshot)CurrentPublishedSnapshot)?.Resync();
CurrentPublishedSnapshot.Resync();
}
private void Notify<T>(ContentStore store, ContentTypeCacheRefresher.JsonPayload[] payloads, Action<List<int>, List<int>, List<int>, List<int>> action)
@@ -797,7 +801,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
public override void Notify(DataTypeCacheRefresher.JsonPayload[] payloads)
public void Notify(DataTypeCacheRefresher.JsonPayload[] payloads)
{
// no cache, nothing we can do
if (Volatile.Read(ref _isReady) == false)
@@ -838,10 +842,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
((PublishedSnapshot)CurrentPublishedSnapshot)?.Resync();
CurrentPublishedSnapshot.Resync();
}
public override void Notify(DomainCacheRefresher.JsonPayload[] payloads)
public void Notify(DomainCacheRefresher.JsonPayload[] payloads)
{
// no cache, nothing we can do
if (Volatile.Read(ref _isReady) == false)
@@ -1013,7 +1017,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
public override IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
public IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
{
EnsureCaches();
@@ -1105,9 +1109,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
return new PublishedSnapshot.PublishedSnapshotElements
{
ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainCache, Options.Create(_globalSettings), VariationContextAccessor),
MediaCache = new MediaCache(previewDefault, mediaSnap, VariationContextAccessor),
MemberCache = new MemberCache(previewDefault, snapshotCache, _serviceContext.MemberService, memberTypeCache, PublishedSnapshotAccessor, VariationContextAccessor, _entitySerializer, _publishedModelFactory),
ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainCache, Options.Create(_globalSettings), _variationContextAccessor),
MediaCache = new MediaCache(previewDefault, mediaSnap, _variationContextAccessor),
MemberCache = new MemberCache(previewDefault, snapshotCache, _serviceContext.MemberService, memberTypeCache, _publishedSnapshotAccessor, _variationContextAccessor, _entitySerializer, _publishedModelFactory),
DomainCache = domainCache,
SnapshotCache = snapshotCache,
ElementsCache = elementsCache
@@ -1115,7 +1119,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
/// <inheritdoc />
public override void Rebuild(
public void Rebuild(
int groupSize = 5000,
IReadOnlyCollection<int> contentTypeIds = null,
IReadOnlyCollection<int> mediaTypeIds = null,
@@ -1158,7 +1162,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
public override string GetStatus()
public string GetStatus()
{
EnsureCaches();
@@ -1184,7 +1188,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
// TODO: This should be async since it's calling into async
public override void Collect()
public void Collect()
{
EnsureCaches();
@@ -1204,5 +1208,12 @@ namespace Umbraco.Web.PublishedCache.NuCache
EnsureCaches();
return _mediaStore;
}
/// <inheritdoc/>
public virtual string StatusUrl => "views/dashboard/settings/publishedsnapshotcache.html";
/// <inheritdoc/>
public void Dispose()
{ }
}
}

View File

@@ -25,7 +25,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
/// <summary>
/// Implements a published snapshot service.
/// </summary>
internal class XmlPublishedSnapshotService : PublishedSnapshotServiceBase
internal class XmlPublishedSnapshotService : IPublishedSnapshotService
{
private readonly XmlStore _xmlStore;
private readonly RoutesCache _routesCache;
@@ -48,13 +48,17 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Constructors
// used in WebBootManager + tests
public XmlPublishedSnapshotService(ServiceContext serviceContext,
public XmlPublishedSnapshotService(
ServiceContext serviceContext,
IPublishedContentTypeFactory publishedContentTypeFactory,
IScopeProvider scopeProvider,
IAppCache requestCache,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
IDocumentRepository documentRepository,
IMediaRepository mediaRepository,
IMemberRepository memberRepository,
IDefaultCultureAccessor defaultCultureAccessor,
ILoggerFactory loggerFactory,
GlobalSettings globalSettings,
@@ -63,9 +67,9 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
IShortStringHelper shortStringHelper,
ISiteDomainHelper siteDomainHelper,
IEntityXmlSerializer entitySerializer,
MainDom mainDom,
bool testing = false, bool enableRepositoryEvents = true)
bool testing = false,
bool enableRepositoryEvents = true)
: this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache,
publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor,
documentRepository, mediaRepository, memberRepository,
@@ -76,13 +80,17 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
}
// used in some tests
internal XmlPublishedSnapshotService(ServiceContext serviceContext,
internal XmlPublishedSnapshotService(
ServiceContext serviceContext,
IPublishedContentTypeFactory publishedContentTypeFactory,
IScopeProvider scopeProvider,
IAppCache requestCache,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
IDocumentRepository documentRepository,
IMediaRepository mediaRepository,
IMemberRepository memberRepository,
IDefaultCultureAccessor defaultCultureAccessor,
ILoggerFactory loggerFactory,
GlobalSettings globalSettings,
@@ -93,8 +101,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
IEntityXmlSerializer entitySerializer,
PublishedContentTypeCache contentTypeCache,
MainDom mainDom,
bool testing, bool enableRepositoryEvents)
: base(publishedSnapshotAccessor, variationContextAccessor)
bool testing,
bool enableRepositoryEvents)
{
_routesCache = new RoutesCache();
_publishedContentTypeFactory = publishedContentTypeFactory;
@@ -120,7 +128,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
_hostingLifetime = hostingLifetime;
}
public override void Dispose()
public void Dispose()
{
_xmlStore.Dispose();
}
@@ -129,7 +137,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Environment
public override bool EnsureEnvironment(out IEnumerable<string> errors)
public bool EnsureEnvironment(out IEnumerable<string> errors)
{
// Test creating/saving/deleting a file in the same location as the content xml file
// NOTE: We cannot modify the xml file directly because a background thread is responsible for
@@ -151,7 +159,7 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Caches
public override IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
public IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
{
// use _requestCache to store recursive properties lookup, etc. both in content
// and media cache. Life span should be the current request. Or, ideally
@@ -169,6 +177,8 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#endregion
public string StatusUrl => throw new System.NotImplementedException();
#region Xml specific
/// <summary>
@@ -215,12 +225,12 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
#region Change management
public override void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged)
public void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged)
{
_xmlStore.Notify(payloads, out draftChanged, out publishedChanged);
}
public override void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged)
public void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged)
{
foreach (var payload in payloads)
PublishedMediaCache.ClearCache(payload.Id);
@@ -228,31 +238,33 @@ namespace Umbraco.Tests.LegacyXmlPublishedCache
anythingChanged = true;
}
public override void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads)
public void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads)
{
_xmlStore.Notify(payloads);
if (payloads.Any(x => x.ItemType == typeof(IContentType).Name))
_routesCache.Clear();
}
public override void Notify(DataTypeCacheRefresher.JsonPayload[] payloads)
public void Notify(DataTypeCacheRefresher.JsonPayload[] payloads)
{
_publishedContentTypeFactory.NotifyDataTypeChanges(payloads.Select(x => x.Id).ToArray());
_xmlStore.Notify(payloads);
}
public override void Notify(DomainCacheRefresher.JsonPayload[] payloads)
public void Notify(DomainCacheRefresher.JsonPayload[] payloads)
{
_routesCache.Clear();
}
#endregion
public override string GetStatus()
public string GetStatus()
{
return "Test status";
}
public override void Rebuild(int groupSize = 5000, IReadOnlyCollection<int> contentTypeIds = null, IReadOnlyCollection<int> mediaTypeIds = null, IReadOnlyCollection<int> memberTypeIds = null) { }
public void Rebuild(int groupSize = 5000, IReadOnlyCollection<int> contentTypeIds = null, IReadOnlyCollection<int> mediaTypeIds = null, IReadOnlyCollection<int> memberTypeIds = null) { }
public void Collect() { }
}
}