Fixes IPublishedShapshot and friends

This commit is contained in:
Shannon
2018-04-27 11:38:50 +10:00
parent ad6a745681
commit 73567ffdce
34 changed files with 435 additions and 431 deletions

View File

@@ -98,7 +98,7 @@ namespace Umbraco.Web.Composing
public static DistributedCache DistributedCache
=> Container.GetInstance<DistributedCache>();
public static IPublishedShapshot PublishedSnapshot
public static IPublishedSnapshot PublishedSnapshot
=> Container.GetInstance<IPublishedSnapshotAccessor>().PublishedSnapshot;
public static EventMessages EventMessages

View File

@@ -8,7 +8,7 @@ namespace Umbraco.Web.PublishedCache
/// </summary>
/// <remarks>A published snapshot is a point-in-time capture of the current state of
/// everything that is "published".</remarks>
public interface IPublishedShapshot
public interface IPublishedSnapshot
{
/// <summary>
/// Gets the <see cref="IPublishedContentCache"/>.

View File

@@ -1,10 +1,10 @@
namespace Umbraco.Web.PublishedCache
{
/// <summary>
/// Provides access to the "current" <see cref="IPublishedShapshot"/>.
/// Provides access to the "current" <see cref="IPublishedSnapshot"/>.
/// </summary>
public interface IPublishedSnapshotAccessor
{
IPublishedShapshot PublishedSnapshot { get; set; }
IPublishedSnapshot PublishedSnapshot { get; set; }
}
}

View File

@@ -6,7 +6,7 @@ using Umbraco.Web.Cache;
namespace Umbraco.Web.PublishedCache
{
/// <summary>
/// Creates and manages <see cref="IPublishedShapshot"/> instances.
/// Creates and manages <see cref="IPublishedSnapshot"/> instances.
/// </summary>
public interface IPublishedSnapshotService : IDisposable
{
@@ -32,7 +32,7 @@ namespace Umbraco.Web.PublishedCache
/// <remarks>If <paramref name="previewToken"/> is null, the snapshot is not previewing, else it
/// is previewing, and what is or is not visible in preview depends on the content of the token,
/// which is not specified and depends on the actual published snapshot service implementation.</remarks>
IPublishedShapshot CreatePublishedSnapshot(string previewToken);
IPublishedSnapshot CreatePublishedSnapshot(string previewToken);
/// <summary>
/// Gets the published snapshot accessor.

View File

@@ -98,7 +98,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private CacheValues GetCacheValues(PropertyCacheLevel cacheLevel)
{
CacheValues cacheValues;
PublishedShapshot publishedSnapshot;
PublishedSnapshot publishedSnapshot;
ICacheProvider cache;
switch (cacheLevel)
{
@@ -115,7 +115,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// elements cache (if we don't want to pollute the elements cache with short-lived
// data) depending on settings
// for members, always cache in the snapshot cache - never pollute elements cache
publishedSnapshot = (PublishedShapshot) _publishedSnapshotAccessor.PublishedSnapshot;
publishedSnapshot = (PublishedSnapshot) _publishedSnapshotAccessor.PublishedSnapshot;
cache = publishedSnapshot == null
? null
: ((_isPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && (_isMember == false)
@@ -125,7 +125,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
break;
case PropertyCacheLevel.Snapshot:
// cache within the snapshot cache
publishedSnapshot = (PublishedShapshot) _publishedSnapshotAccessor.PublishedSnapshot;
publishedSnapshot = (PublishedSnapshot) _publishedSnapshotAccessor.PublishedSnapshot;
cache = publishedSnapshot?.SnapshotCache;
cacheValues = GetCacheValues(cache);
break;

View File

@@ -102,10 +102,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
// this is for tests purposes
// args are: current published snapshot (may be null), previewing, content id - returns: content
internal static Func<IPublishedShapshot, bool, int, IPublishedContent> GetContentByIdFunc { get; set; }
internal static Func<IPublishedSnapshot, bool, int, IPublishedContent> GetContentByIdFunc { get; set; }
= (publishedShapshot, previewing, id) => publishedShapshot.Content.GetById(previewing, id);
internal static Func<IPublishedShapshot, bool, int, IPublishedContent> GetMediaByIdFunc { get; set; }
internal static Func<IPublishedSnapshot, bool, int, IPublishedContent> GetMediaByIdFunc { get; set; }
= (publishedShapshot, previewing, id) => publishedShapshot.Media.GetById(previewing, id);
private IPublishedContent GetContentById(bool previewing, int id)
@@ -289,7 +289,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// beware what you use that one for - you don't want to cache its result
private ICacheProvider GetAppropriateCache()
{
var publishedSnapshot = (PublishedShapshot)_publishedSnapshotAccessor.PublishedSnapshot;
var publishedSnapshot = (PublishedSnapshot)_publishedSnapshotAccessor.PublishedSnapshot;
var cache = publishedSnapshot == null
? null
: ((IsPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && (ItemType != PublishedItemType.Member)
@@ -300,7 +300,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private ICacheProvider GetCurrentSnapshotCache()
{
var publishedSnapshot = (PublishedShapshot)_publishedSnapshotAccessor.PublishedSnapshot;
var publishedSnapshot = (PublishedSnapshot)_publishedSnapshotAccessor.PublishedSnapshot;
return publishedSnapshot?.SnapshotCache;
}

View File

@@ -5,7 +5,7 @@ using Umbraco.Core.Cache;
namespace Umbraco.Web.PublishedCache.NuCache
{
// implements published snapshot
internal class PublishedShapshot : IPublishedShapshot, IDisposable
internal class PublishedSnapshot : IPublishedSnapshot, IDisposable
{
private readonly PublishedSnapshotService _service;
private bool _defaultPreview;
@@ -13,7 +13,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Constructors
public PublishedShapshot(PublishedSnapshotService service, bool defaultPreview)
public PublishedSnapshot(PublishedSnapshotService service, bool defaultPreview)
{
_service = service;
_defaultPreview = defaultPreview;
@@ -72,13 +72,13 @@ namespace Umbraco.Web.PublishedCache.NuCache
private class ForcedPreviewObject : DisposableObject
{
private readonly PublishedShapshot _publishedShapshot;
private readonly PublishedSnapshot _publishedSnapshot;
private readonly bool _origPreview;
private readonly Action<bool> _callback;
public ForcedPreviewObject(PublishedShapshot publishedShapshot, bool preview, Action<bool> callback)
public ForcedPreviewObject(PublishedSnapshot publishedShapshot, bool preview, Action<bool> callback)
{
_publishedShapshot = publishedShapshot;
_publishedSnapshot = publishedShapshot;
_callback = callback;
// save and force
@@ -89,7 +89,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
protected override void DisposeResources()
{
// restore
_publishedShapshot._defaultPreview = _origPreview;
_publishedSnapshot._defaultPreview = _origPreview;
_callback?.Invoke(_origPreview);
}
}

View File

@@ -533,7 +533,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
if (draftChanged || publishedChanged)
((PublishedShapshot)CurrentPublishedShapshot).Resync();
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
}
private void NotifyLocked(IEnumerable<ContentCacheRefresher.JsonPayload> payloads, out bool draftChanged, out bool publishedChanged)
@@ -630,7 +630,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
if (anythingChanged)
((PublishedShapshot)CurrentPublishedShapshot).Resync();
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
}
private void NotifyLocked(IEnumerable<MediaCacheRefresher.JsonPayload> payloads, out bool anythingChanged)
@@ -719,7 +719,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
Notify<IContentType>(_contentStore, payloads, RefreshContentTypesLocked);
Notify<IMediaType>(_mediaStore, payloads, RefreshMediaTypesLocked);
((PublishedShapshot)CurrentPublishedShapshot).Resync();
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
}
private void Notify<T>(ContentStore store, ContentTypeCacheRefresher.JsonPayload[] payloads, Action<IEnumerable<int>, IEnumerable<int>, IEnumerable<int>, IEnumerable<int>> action)
@@ -796,7 +796,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
}
((PublishedShapshot)CurrentPublishedShapshot).Resync();
((PublishedSnapshot)CurrentPublishedSnapshot).Resync();
}
public override void Notify(DomainCacheRefresher.JsonPayload[] payloads)
@@ -945,17 +945,17 @@ namespace Umbraco.Web.PublishedCache.NuCache
private long _contentGen, _mediaGen, _domainGen;
private ICacheProvider _elementsCache;
public override IPublishedShapshot CreatePublishedSnapshot(string previewToken)
public override IPublishedSnapshot CreatePublishedSnapshot(string previewToken)
{
// no cache, no joy
if (_isReady == false)
throw new InvalidOperationException("The published snapshot service has not properly initialized.");
var preview = previewToken.IsNullOrWhiteSpace() == false;
return new PublishedShapshot(this, preview);
return new PublishedSnapshot(this, preview);
}
public PublishedShapshot.PublishedSnapshotElements GetElements(bool previewDefault)
public PublishedSnapshot.PublishedSnapshotElements GetElements(bool previewDefault)
{
// note: using ObjectCacheRuntimeCacheProvider for elements and snapshot caches
// is not recommended because it creates an inner MemoryCache which is a heavy
@@ -996,7 +996,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// a MaxValue to make sure this one runs last, and it should be ok
scopeContext.Enlist("Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.Resync", () => this, (completed, svc) =>
{
((PublishedShapshot)svc.CurrentPublishedShapshot).Resync();
((PublishedSnapshot)svc.CurrentPublishedSnapshot).Resync();
}, int.MaxValue);
}
@@ -1017,7 +1017,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var domainCache = new DomainCache(domainSnap);
var domainHelper = new DomainHelper(domainCache, _siteDomainHelper);
return new PublishedShapshot.PublishedSnapshotElements
return new PublishedSnapshot.PublishedSnapshotElements
{
ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainHelper, _globalSettings, _serviceContext.LocalizationService),
MediaCache = new MediaCache(previewDefault, mediaSnap, snapshotCache, elementsCache),

View File

@@ -15,9 +15,9 @@ namespace Umbraco.Web.PublishedCache
// note: NOT setting _publishedSnapshotAccessor.PublishedSnapshot here because it is the
// responsibility of the caller to manage what the 'current' facade is
public abstract IPublishedShapshot CreatePublishedSnapshot(string previewToken);
public abstract IPublishedSnapshot CreatePublishedSnapshot(string previewToken);
protected IPublishedShapshot CurrentPublishedShapshot => PublishedSnapshotAccessor.PublishedSnapshot;
protected IPublishedSnapshot CurrentPublishedSnapshot => PublishedSnapshotAccessor.PublishedSnapshot;
public abstract bool EnsureEnvironment(out IEnumerable<string> errors);

View File

@@ -11,13 +11,13 @@ namespace Umbraco.Web.PublishedCache
_umbracoContextAccessor = umbracoContextAccessor;
}
public IPublishedShapshot PublishedSnapshot
public IPublishedSnapshot PublishedSnapshot
{
get
{
var umbracoContext = _umbracoContextAccessor.UmbracoContext;
if (umbracoContext == null) throw new Exception("The IUmbracoContextAccessor could not provide an UmbracoContext.");
return umbracoContext.PublishedShapshot;
return umbracoContext.PublishedSnapshot;
}
set

View File

@@ -7,13 +7,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
/// <summary>
/// Implements a published snapshot.
/// </summary>
class PublishedShapshot : IPublishedShapshot
class PublishedSnapshot : IPublishedSnapshot
{
/// <summary>
/// Initializes a new instance of the <see cref="PublishedShapshot"/> class with a content cache
/// Initializes a new instance of the <see cref="PublishedSnapshot"/> class with a content cache
/// and a media cache.
/// </summary>
public PublishedShapshot(
public PublishedSnapshot(
PublishedContentCache contentCache,
PublishedMediaCache mediaCache,
PublishedMemberCache memberCache,

View File

@@ -139,7 +139,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
#region Caches
public override IPublishedShapshot CreatePublishedSnapshot(string previewToken)
public override 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
@@ -148,7 +148,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var domainCache = new DomainCache(_domainService, _localizationService);
return new PublishedShapshot(
return new PublishedSnapshot(
new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _siteDomainHelper, _contentTypeCache, _routesCache, previewToken),
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache),
new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache),

View File

@@ -1250,7 +1250,7 @@ ORDER BY umbracoNode.level, umbracoNode.sortOrder";
private void ResyncCurrentPublishedSnapshot(XmlDocument xml)
{
var publishedSnapshot = (PublishedShapshot) _publishedSnapshotAccessor.PublishedSnapshot;
var publishedSnapshot = (PublishedSnapshot) _publishedSnapshotAccessor.PublishedSnapshot;
if (publishedSnapshot == null) return;
((PublishedContentCache) publishedSnapshot.Content).Resync(xml);
((PublishedMediaCache) publishedSnapshot.Media).Resync();

View File

@@ -54,7 +54,7 @@ namespace Umbraco.Web.Routing
}
if (node != null)
{
var d = DomainHelper.FindWildcardDomainInPath(frequest.UmbracoContext.PublishedShapshot.Domains.GetAll(true), node.Path, null);
var d = DomainHelper.FindWildcardDomainInPath(frequest.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), node.Path, null);
if (d != null)
errorCulture = d.Culture;
}

View File

@@ -266,7 +266,7 @@ namespace Umbraco.Web.Routing
_logger.Debug<PublishedRouter>(() => $"{tracePrefix}Uri=\"{request.Uri}\"");
// try to find a domain matching the current request
var domainAndUri = DomainHelper.DomainForUri(request.UmbracoContext.PublishedShapshot.Domains.GetAll(false), request.Uri);
var domainAndUri = DomainHelper.DomainForUri(request.UmbracoContext.PublishedSnapshot.Domains.GetAll(false), request.Uri);
// handle domain - always has a contentId and a culture
if (domainAndUri != null)
@@ -311,7 +311,7 @@ namespace Umbraco.Web.Routing
var nodePath = request.PublishedContent.Path;
_logger.Debug<PublishedRouter>(() => $"{tracePrefix}Path=\"{nodePath}\"");
var rootNodeId = request.HasDomain ? request.Domain.ContentId : (int?)null;
var domain = DomainHelper.FindWildcardDomainInPath(request.UmbracoContext.PublishedShapshot.Domains.GetAll(true), nodePath, rootNodeId);
var domain = DomainHelper.FindWildcardDomainInPath(request.UmbracoContext.PublishedSnapshot.Domains.GetAll(true), nodePath, rootNodeId);
// always has a contentId and a culture
if (domain != null)
@@ -602,14 +602,14 @@ namespace Umbraco.Web.Routing
var loginPageId = publicAccessAttempt.Result.LoginNodeId;
if (loginPageId != request.PublishedContent.Id)
request.PublishedContent = request.UmbracoContext.PublishedShapshot.Content.GetById(loginPageId);
request.PublishedContent = request.UmbracoContext.PublishedSnapshot.Content.GetById(loginPageId);
}
else if (_services.PublicAccessService.HasAccess(request.PublishedContent.Id, _services.ContentService, GetRolesForLogin(membershipHelper.CurrentUserName)) == false)
{
_logger.Debug<PublishedRouter>(() => $"{tracePrefix}Current member has not access, redirect to error page");
var errorPageId = publicAccessAttempt.Result.NoAccessNodeId;
if (errorPageId != request.PublishedContent.Id)
request.PublishedContent = request.UmbracoContext.PublishedShapshot.Content.GetById(errorPageId);
request.PublishedContent = request.UmbracoContext.PublishedSnapshot.Content.GetById(errorPageId);
}
else
{

View File

@@ -94,7 +94,7 @@ namespace Umbraco.Web.Security
_umbracoContext = umbracoContext;
_membershipProvider = membershipProvider;
_roleProvider = roleProvider;
_memberCache = umbracoContext.PublishedShapshot.Members;
_memberCache = umbracoContext.PublishedSnapshot.Members;
// helpers are *not* instanciated by the container so we have to
// get our dependencies injected manually, through properties.

View File

@@ -342,6 +342,7 @@
<Compile Include="PropertyEditors\ValueConverters\MemberPickerValueConverter.cs" />
<Compile Include="PropertyEditors\ValueConverters\MultiNodeTreePickerValueConverter.cs" />
<Compile Include="PropertyEditors\ValueListUniqueValueValidator.cs" />
<Compile Include="PublishedCache\IPublishedSnapshot.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\BTree.ContentDataSerializer.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\BTree.ContentNodeKitSerializer.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\BTree.DictionaryOfCultureVariationSerializer.cs" />
@@ -351,13 +352,13 @@
<Compile Include="PublishedCache\NuCache\DataSource\PropertyData.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\SerializerBase.cs" />
<Compile Include="PublishedCache\NuCache\NuCacheComponent.cs" />
<Compile Include="PublishedCache\NuCache\PublishedSnapshot.cs" />
<Compile Include="PublishedCache\PublishedElement.cs" />
<Compile Include="PublishedCache\PublishedElementPropertyBase.cs" />
<Compile Include="Models\Trees\DisableUser.cs" />
<Compile Include="PropertyEditors\ValueConverters\ContentPickerValueConverter.cs" />
<Compile Include="PublishedCache\PublishedSnapshotServiceBase.cs" />
<Compile Include="PublishedCache\IDomainCache.cs" />
<Compile Include="PublishedCache\IPublishedShapshot.cs" />
<Compile Include="PublishedCache\IPublishedSnapshotAccessor.cs" />
<Compile Include="PublishedCache\IPublishedSnapshotService.cs" />
<Compile Include="PublishedCache\IPublishedMemberCache.cs" />
@@ -371,7 +372,6 @@
<Compile Include="PublishedCache\NuCache\DataSource\ContentSourceDto.cs" />
<Compile Include="PublishedCache\NuCache\DataSource\Database.cs" />
<Compile Include="PublishedCache\NuCache\DomainCache.cs" />
<Compile Include="PublishedCache\NuCache\PublishedShapshot.cs" />
<Compile Include="PublishedCache\NuCache\PublishedSnapshotService.cs" />
<Compile Include="PublishedCache\NuCache\MediaCache.cs" />
<Compile Include="PublishedCache\NuCache\MemberCache.cs" />
@@ -389,7 +389,7 @@
<Compile Include="PublishedCache\PublishedContentTypeCache.cs" />
<Compile Include="PublishedCache\UmbracoContextPublishedSnapshotAccessor.cs" />
<Compile Include="PublishedCache\XmlPublishedCache\DomainCache.cs" />
<Compile Include="PublishedCache\XmlPublishedCache\PublishedShapshot.cs" />
<Compile Include="PublishedCache\XmlPublishedCache\PublishedSnapshot.cs" />
<Compile Include="PublishedCache\XmlPublishedCache\PublishedSnapshotService.cs" />
<Compile Include="PublishedCache\XmlPublishedCache\PreviewContent.cs" />
<Compile Include="PublishedCache\XmlPublishedCache\PublishedMemberCache.cs" />

View File

@@ -18,7 +18,7 @@ namespace Umbraco.Web
public class UmbracoContext : DisposableObject, IDisposeOnRequestEnd
{
private readonly IGlobalSettings _globalSettings;
private readonly Lazy<IPublishedShapshot> _publishedSnapshot;
private readonly Lazy<IPublishedSnapshot> _publishedSnapshot;
private DomainHelper _domainHelper;
private string _previewToken;
private bool? _previewing;
@@ -125,7 +125,7 @@ namespace Umbraco.Web
Security = webSecurity;
// beware - we cannot expect a current user here, so detecting preview mode must be a lazy thing
_publishedSnapshot = new Lazy<IPublishedShapshot>(() => publishedSnapshotService.CreatePublishedSnapshot(PreviewToken));
_publishedSnapshot = new Lazy<IPublishedSnapshot>(() => publishedSnapshotService.CreatePublishedSnapshot(PreviewToken));
// set the urls...
// NOTE: The request will not be available during app startup so we can only set this to an absolute URL of localhost, this
@@ -178,7 +178,7 @@ namespace Umbraco.Web
/// <summary>
/// Gets the published snapshot.
/// </summary>
public IPublishedShapshot PublishedShapshot => _publishedSnapshot.Value;
public IPublishedSnapshot PublishedSnapshot => _publishedSnapshot.Value;
// for unit tests
internal bool HasPublishedSnapshot => _publishedSnapshot.IsValueCreated;
@@ -186,12 +186,12 @@ namespace Umbraco.Web
/// <summary>
/// Gets the published content cache.
/// </summary>
public IPublishedContentCache ContentCache => PublishedShapshot.Content;
public IPublishedContentCache ContentCache => PublishedSnapshot.Content;
/// <summary>
/// Gets the published media cache.
/// </summary>
public IPublishedMediaCache MediaCache => PublishedShapshot.Media;
public IPublishedMediaCache MediaCache => PublishedSnapshot.Media;
/// <summary>
/// Boolean value indicating whether the current request is a front-end umbraco request
@@ -227,7 +227,7 @@ namespace Umbraco.Web
internal DomainHelper GetDomainHelper(ISiteDomainHelper siteDomainHelper)
{
if (_domainHelper == null)
_domainHelper = new DomainHelper(PublishedShapshot.Domains, siteDomainHelper);
_domainHelper = new DomainHelper(PublishedSnapshot.Domains, siteDomainHelper);
return _domainHelper;
}
@@ -314,7 +314,7 @@ namespace Umbraco.Web
internal IDisposable ForcedPreview(bool preview)
{
InPreviewMode = preview;
return PublishedShapshot.ForcedPreview(preview, orig => InPreviewMode = orig);
return PublishedSnapshot.ForcedPreview(preview, orig => InPreviewMode = orig);
}
private HttpRequestBase GetRequestFromContext()