Injecting Umbraco Context Accessor and not saving the url on the class

This commit is contained in:
Bjarke Berg
2019-01-23 14:16:42 +01:00
parent fedf0c78de
commit f8b52a57c3
24 changed files with 194 additions and 100 deletions

View File

@@ -34,10 +34,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
DateTime createDate, int creatorId,
ContentData draftData, ContentData publishedData,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor)
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor)
: this(id, uid, level, path, sortOrder, parentContentId, createDate, creatorId)
{
SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor);
SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor);
}
// 2-phases ctor, phase 1
@@ -59,7 +60,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
// two-phase ctor, phase 2
public void SetContentTypeAndData(PublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
public void SetContentTypeAndData(PublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor)
{
ContentType = contentType;
@@ -67,13 +68,13 @@ namespace Umbraco.Web.PublishedCache.NuCache
throw new ArgumentException("Both draftData and publishedData cannot be null at the same time.");
if (draftData != null)
Draft = new PublishedContent(this, draftData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
Draft = new PublishedContent(this, draftData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor).CreateModel();
if (publishedData != null)
Published = new PublishedContent(this, publishedData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
Published = new PublishedContent(this, publishedData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor).CreateModel();
}
// clone parent
private ContentNode(ContentNode origin)
private ContentNode(ContentNode origin, IUmbracoContextAccessor umbracoContextAccessor)
{
// everything is the same, except for the child items
// list which is a clone of the original list
@@ -91,14 +92,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft);
var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published);
Draft = originDraft == null ? null : new PublishedContent(this, originDraft).CreateModel();
Published = originPublished == null ? null : new PublishedContent(this, originPublished).CreateModel();
Draft = originDraft == null ? null : new PublishedContent(this, originDraft, umbracoContextAccessor).CreateModel();
Published = originPublished == null ? null : new PublishedContent(this, originPublished, umbracoContextAccessor).CreateModel();
ChildContentIds = new List<int>(origin.ChildContentIds); // needs to be *another* list
}
// clone with new content type
public ContentNode(ContentNode origin, PublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
public ContentNode(ContentNode origin, PublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor)
{
Id = origin.Id;
Uid = origin.Uid;
@@ -113,8 +114,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft);
var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published);
Draft = originDraft == null ? null : new PublishedContent(this, originDraft._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
Published = originPublished == null ? null : new PublishedContent(this, originPublished._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
Draft = originDraft == null ? null : new PublishedContent(this, originDraft._contentData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor).CreateModel();
Published = originPublished == null ? null : new PublishedContent(this, originPublished._contentData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor).CreateModel();
ChildContentIds = origin.ChildContentIds; // can be the *same* list
}
@@ -137,9 +138,11 @@ namespace Umbraco.Web.PublishedCache.NuCache
public IPublishedContent Draft;
public IPublishedContent Published;
public ContentNode CloneParent(IPublishedSnapshotAccessor publishedSnapshotAccessor)
public ContentNode CloneParent(
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IUmbracoContextAccessor umbracoContextAccessor)
{
return new ContentNode(this);
return new ContentNode(this, umbracoContextAccessor);
}
public ContentNodeKit ToKit()

View File

@@ -17,9 +17,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
public static ContentNodeKit Null { get; } = new ContentNodeKit { ContentTypeId = -1 };
public void Build(PublishedContentType contentType, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, bool canBePublished)
public void Build(
PublishedContentType contentType,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
bool canBePublished,
IUmbracoContextAccessor umbracoContextAccessor)
{
Node.SetContentTypeAndData(contentType, DraftData, canBePublished ? PublishedData : null, publishedSnapshotAccessor, variationContextAccessor);
Node.SetContentTypeAndData(contentType, DraftData, canBePublished ? PublishedData : null, publishedSnapshotAccessor, variationContextAccessor,umbracoContextAccessor);
}
}
}

View File

@@ -20,6 +20,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly ConcurrentDictionary<int, LinkedNode<ContentNode>> _contentNodes;
private readonly ConcurrentDictionary<int, LinkedNode<object>> _contentRootNodes;
private readonly ConcurrentDictionary<int, LinkedNode<PublishedContentType>> _contentTypesById;
@@ -44,10 +45,16 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Ctor
public ContentStore(IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, ILogger logger, BPlusTree<int, ContentNodeKit> localDb = null)
public ContentStore(
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
ILogger logger,
BPlusTree<int, ContentNodeKit> localDb = null)
{
_publishedSnapshotAccessor = publishedSnapshotAccessor;
_variationContextAccessor = variationContextAccessor;
_umbracoContextAccessor = umbracoContextAccessor;
_logger = logger;
_localDb = localDb;
@@ -279,7 +286,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (node == null) continue;
var contentTypeId = node.ContentType.Id;
if (index.TryGetValue(contentTypeId, out PublishedContentType contentType) == false) continue;
SetValueLocked(_contentNodes, node.Id, new ContentNode(node, contentType, _publishedSnapshotAccessor, _variationContextAccessor));
SetValueLocked(_contentNodes, node.Id, new ContentNode(node, contentType, _publishedSnapshotAccessor, _variationContextAccessor, _umbracoContextAccessor));
}
}
finally
@@ -393,7 +400,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
_contentNodes.TryGetValue(id, out LinkedNode<ContentNode> link);
if (link?.Value == null)
continue;
var node = new ContentNode(link.Value, contentType, _publishedSnapshotAccessor, _variationContextAccessor);
var node = new ContentNode(link.Value, contentType, _publishedSnapshotAccessor, _variationContextAccessor, _umbracoContextAccessor);
SetValueLocked(_contentNodes, id, node);
if (_localDb != null) RegisterChange(id, node.ToKit());
}
@@ -419,7 +426,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var canBePublished = ParentPublishedLocked(kit);
// and use
kit.Build(link.Value, _publishedSnapshotAccessor, _variationContextAccessor, canBePublished);
kit.Build(link.Value, _publishedSnapshotAccessor, _variationContextAccessor, canBePublished, _umbracoContextAccessor);
return true;
}
@@ -631,7 +638,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var link = GetParentLink(content);
var parent = link.Value;
if (link.Gen < _liveGen)
parent = parent.CloneParent(_publishedSnapshotAccessor);
parent = parent.CloneParent(_publishedSnapshotAccessor, _umbracoContextAccessor);
parent.ChildContentIds.Remove(content.Id);
if (link.Gen < _liveGen)
SetValueLocked(_contentNodes, parent.Id, parent);
@@ -670,7 +677,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var link = GetParentLink(content);
var parent = link.Value;
if (link.Gen < _liveGen)
parent = parent.CloneParent(_publishedSnapshotAccessor);
parent = parent.CloneParent(_publishedSnapshotAccessor, _umbracoContextAccessor);
parent.ChildContentIds.Add(content.Id);
if (link.Gen < _liveGen)
SetValueLocked(_contentNodes, parent.Id, parent);

View File

@@ -17,18 +17,22 @@ namespace Umbraco.Web.PublishedCache.NuCache
internal class MemberCache : IPublishedMemberCache, INavigableData
{
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
public readonly IVariationContextAccessor VariationContextAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IEntityXmlSerializer _entitySerializer;
private readonly IAppCache _snapshotCache;
private readonly IMemberService _memberService;
private readonly PublishedContentTypeCache _contentTypeCache;
private readonly bool _previewDefault;
public MemberCache(bool previewDefault, IAppCache snapshotCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IEntityXmlSerializer entitySerializer)
public MemberCache(bool previewDefault, IAppCache snapshotCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IUmbracoContextAccessor umbracoContextAccessor, IEntityXmlSerializer entitySerializer)
{
_snapshotCache = snapshotCache;
_publishedSnapshotAccessor = publishedSnapshotAccessor;
VariationContextAccessor = variationContextAccessor;
_umbracoContextAccessor = umbracoContextAccessor;
_entitySerializer = entitySerializer;
_memberService = memberService;
_previewDefault = previewDefault;
@@ -64,14 +68,14 @@ namespace Umbraco.Web.PublishedCache.NuCache
var member = _memberService.GetById(memberId);
return member == null
? null
: PublishedMember.Create(member, GetContentType(member.ContentTypeId), _previewDefault, _publishedSnapshotAccessor, VariationContextAccessor);
: PublishedMember.Create(member, GetContentType(member.ContentTypeId), _previewDefault, _publishedSnapshotAccessor, VariationContextAccessor, _umbracoContextAccessor);
});
}
private IPublishedContent /*IPublishedMember*/ GetById(IMember member, bool previewing)
{
return GetCacheItem(CacheKeys.MemberCacheMember("ById", _previewDefault, member.Id), () =>
PublishedMember.Create(member, GetContentType(member.ContentTypeId), previewing, _publishedSnapshotAccessor, VariationContextAccessor));
PublishedMember.Create(member, GetContentType(member.ContentTypeId), previewing, _publishedSnapshotAccessor, VariationContextAccessor, _umbracoContextAccessor));
}
public IPublishedContent /*IPublishedMember*/ GetByProviderKey(object key)
@@ -106,7 +110,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
public IPublishedContent /*IPublishedMember*/ GetByMember(IMember member)
{
return PublishedMember.Create(member, GetContentType(member.ContentTypeId), _previewDefault, _publishedSnapshotAccessor, VariationContextAccessor);
return PublishedMember.Create(member, GetContentType(member.ContentTypeId), _previewDefault, _publishedSnapshotAccessor, VariationContextAccessor, _umbracoContextAccessor);
}
public IEnumerable<IPublishedContent> GetAtRoot(bool preview)
@@ -114,7 +118,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// because members are flat (not a tree) everything is at root
// because we're loading everything... let's just not cache?
var members = _memberService.GetAllMembers();
return members.Select(m => PublishedMember.Create(m, GetContentType(m.ContentTypeId), preview, _publishedSnapshotAccessor, VariationContextAccessor));
return members.Select(m => PublishedMember.Create(m, GetContentType(m.ContentTypeId), preview, _publishedSnapshotAccessor, VariationContextAccessor, _umbracoContextAccessor));
}
public XPathNavigator CreateNavigator()

View File

@@ -14,6 +14,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
internal class PublishedContent : PublishedContentBase
{
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly ContentNode _contentNode;
// ReSharper disable once InconsistentNaming
internal readonly ContentData _contentData; // internal for ContentNode cloning
@@ -22,11 +23,17 @@ namespace Umbraco.Web.PublishedCache.NuCache
#region Constructors
public PublishedContent(ContentNode contentNode, ContentData contentData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
public PublishedContent(
ContentNode contentNode,
ContentData contentData,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor) :base(umbracoContextAccessor)
{
_contentNode = contentNode;
_contentData = contentData;
_publishedSnapshotAccessor = publishedSnapshotAccessor;
_umbracoContextAccessor = umbracoContextAccessor;
VariationContextAccessor = variationContextAccessor;
_urlSegment = _contentData.Name.ToUrlSegment();
@@ -66,7 +73,10 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
// (see ContentNode.CloneParent)
public PublishedContent(ContentNode contentNode, PublishedContent origin)
public PublishedContent(
ContentNode contentNode,
PublishedContent origin,
IUmbracoContextAccessor umbracoContextAccessor) :base(umbracoContextAccessor)
{
_contentNode = contentNode;
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
@@ -83,7 +93,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
}
// clone for previewing as draft a published content that is published and has no draft
private PublishedContent(PublishedContent origin)
private PublishedContent(
PublishedContent origin,
IUmbracoContextAccessor umbracoContextAccessor) :base(umbracoContextAccessor)
{
_publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
VariationContextAccessor = origin.VariationContextAccessor;
@@ -433,8 +445,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
return this;
var cache = GetAppropriateCache();
if (cache == null) return new PublishedContent(this).CreateModel();
return (IPublishedContent)cache.Get(AsPreviewingCacheKey, () => new PublishedContent(this).CreateModel());
if (cache == null) return new PublishedContent(this, _umbracoContextAccessor).CreateModel();
return (IPublishedContent)cache.Get(AsPreviewingCacheKey, () => new PublishedContent(this, _umbracoContextAccessor).CreateModel());
}
// used by Navigable.Source,...

View File

@@ -15,13 +15,26 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
private readonly IMember _member;
private PublishedMember(IMember member, ContentNode contentNode, ContentData contentData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
: base(contentNode, contentData, publishedSnapshotAccessor, variationContextAccessor)
private PublishedMember(
IMember member,
ContentNode contentNode,
ContentData contentData,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor
)
: base(contentNode, contentData, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor)
{
_member = member;
}
public static IPublishedContent Create(IMember member, PublishedContentType contentType, bool previewing, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
public static IPublishedContent Create(
IMember member,
PublishedContentType contentType,
bool previewing,
IPublishedSnapshotAccessor publishedSnapshotAccessor,
IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor)
{
var d = new ContentData
{
@@ -37,7 +50,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
member.Level, member.Path, member.SortOrder,
member.ParentId,
member.CreateDate, member.CreatorId);
return new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor).CreateModel();
return new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor).CreateModel();
}
private static Dictionary<string, PropertyData[]> GetPropertyValues(PublishedContentType contentType, IMember member)

View File

@@ -32,6 +32,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
private readonly ServiceContext _serviceContext;
private readonly IPublishedContentTypeFactory _publishedContentTypeFactory;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IScopeProvider _scopeProvider;
private readonly IDataSource _dataSource;
private readonly ILogger _logger;
@@ -80,7 +81,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
public PublishedSnapshotService(Options options, IMainDom mainDom, IRuntimeState runtime,
ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IdkMap idkMap,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
ILogger logger, IScopeProvider scopeProvider,
IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IScopeProvider scopeProvider,
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
IDefaultCultureAccessor defaultCultureAccessor,
IDataSource dataSource, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper,
@@ -92,6 +93,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
_serviceContext = serviceContext;
_publishedContentTypeFactory = publishedContentTypeFactory;
_umbracoContextAccessor = umbracoContextAccessor;
_dataSource = dataSource;
_logger = logger;
_scopeProvider = scopeProvider;
@@ -148,13 +150,13 @@ 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 dbs or it should populate them from sql
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger, _localContentDb);
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger, _localMediaDb);
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, _umbracoContextAccessor, logger, _localContentDb);
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, _umbracoContextAccessor, logger, _localMediaDb);
}
else
{
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger);
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, logger);
_contentStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, _umbracoContextAccessor, logger);
_mediaStore = new ContentStore(publishedSnapshotAccessor, variationContextAccessor, _umbracoContextAccessor, logger);
}
_domainStore = new SnapDictionary<int, Domain>();
@@ -1015,7 +1017,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
{
ContentCache = new ContentCache(previewDefault, contentSnap, snapshotCache, elementsCache, domainHelper, _globalSettings, _serviceContext.LocalizationService),
MediaCache = new MediaCache(previewDefault, mediaSnap, snapshotCache, elementsCache),
MemberCache = new MemberCache(previewDefault, snapshotCache, _serviceContext.MemberService, memberTypeCache, PublishedSnapshotAccessor, VariationContextAccessor, _entitySerializer),
MemberCache = new MemberCache(previewDefault, snapshotCache, _serviceContext.MemberService, memberTypeCache, PublishedSnapshotAccessor, VariationContextAccessor, _umbracoContextAccessor, _entitySerializer),
DomainCache = domainCache,
SnapshotCache = snapshotCache,
ElementsCache = elementsCache

View File

@@ -19,7 +19,11 @@ namespace Umbraco.Web.PublishedCache
private readonly IPublishedProperty[] _properties;
private readonly PublishedContentType _publishedMemberType;
public PublishedMember(IMember member, PublishedContentType publishedMemberType)
public PublishedMember(
IMember member,
PublishedContentType publishedMemberType,
IUmbracoContextAccessor umbracoContextAccessor)
:base(umbracoContextAccessor)
{
_member = member ?? throw new ArgumentNullException(nameof(member));
_membershipUser = member;

View File

@@ -38,7 +38,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
IAppCache appCache,
PublishedContentTypeCache contentTypeCache,
XPathNavigator nav,
bool fromExamine)
bool fromExamine,
IUmbracoContextAccessor umbracoContextAccessor)
:base(umbracoContextAccessor)
{
if (valueDictionary == null) throw new ArgumentNullException(nameof(valueDictionary));
if (getParent == null) throw new ArgumentNullException(nameof(getParent));

View File

@@ -17,6 +17,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
{
private readonly IAppCache _appCache;
private readonly IGlobalSettings _globalSettings;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly RoutesCache _routesCache;
private readonly IDomainCache _domainCache;
private readonly DomainHelper _domainHelper;
@@ -33,6 +34,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
IAppCache appCache, // an IAppCache that should be at request-level
IGlobalSettings globalSettings,
ISiteDomainHelper siteDomainHelper,
IUmbracoContextAccessor umbracoContextAccessor,
PublishedContentTypeCache contentTypeCache, // a PublishedContentType cache
RoutesCache routesCache, // a RoutesCache
string previewToken) // a preview token string (or null if not previewing)
@@ -40,6 +42,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
{
_appCache = appCache;
_globalSettings = globalSettings;
_umbracoContextAccessor = umbracoContextAccessor;
_routesCache = routesCache; // may be null for unit-testing
_contentTypeCache = contentTypeCache;
_domainCache = domainCache;
@@ -315,13 +318,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private IPublishedContent ConvertToDocument(XmlNode xmlNode, bool isPreviewing)
{
return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache);
return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache,_umbracoContextAccessor);
}
private IEnumerable<IPublishedContent> ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing)
{
return xmlNodes.Cast<XmlNode>()
.Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache));
.Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache, _umbracoContextAccessor));
}
#endregion

View File

@@ -41,11 +41,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private readonly XmlStore _xmlStore;
private readonly PublishedContentTypeCache _contentTypeCache;
private readonly IEntityXmlSerializer _entitySerializer;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
// must be specified by the ctor
private readonly IAppCache _appCache;
public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer)
public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService,
IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer,
IUmbracoContextAccessor umbracoContextAccessor)
: base(false)
{
_mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService));
@@ -55,6 +58,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
_xmlStore = xmlStore;
_contentTypeCache = contentTypeCache;
_entitySerializer = entitySerializer;
_umbracoContextAccessor = umbracoContextAccessor;
}
/// <summary>
@@ -666,7 +670,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
_appCache,
_contentTypeCache,
cacheValues.XPath, // though, outside of tests, that should be null
cacheValues.FromExamine
cacheValues.FromExamine,
_umbracoContextAccessor
);
return content.CreateModel();
}

View File

@@ -16,13 +16,16 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private readonly IAppCache _requestCache;
private readonly XmlStore _xmlStore;
private readonly PublishedContentTypeCache _contentTypeCache;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
public PublishedMemberCache(XmlStore xmlStore, IAppCache requestCache, IMemberService memberService, PublishedContentTypeCache contentTypeCache)
public PublishedMemberCache(XmlStore xmlStore, IAppCache requestCache, IMemberService memberService,
PublishedContentTypeCache contentTypeCache, IUmbracoContextAccessor umbracoContextAccessor)
{
_requestCache = requestCache;
_memberService = memberService;
_xmlStore = xmlStore;
_contentTypeCache = contentTypeCache;
_umbracoContextAccessor = umbracoContextAccessor;
}
public IPublishedContent GetByProviderKey(object key)
@@ -39,7 +42,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var result = _memberService.GetByProviderKey(key);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
return new PublishedMember(result, type).CreateModel();
return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
});
}
@@ -57,7 +60,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var result = _memberService.GetById(memberId);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
return new PublishedMember(result, type).CreateModel();
return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
});
}
@@ -75,7 +78,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var result = _memberService.GetByUsername(username);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
return new PublishedMember(result, type).CreateModel();
return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
});
}
@@ -93,14 +96,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var result = _memberService.GetByEmail(email);
if (result == null) return null;
var type = _contentTypeCache.Get(PublishedItemType.Member, result.ContentTypeId);
return new PublishedMember(result, type).CreateModel();
return new PublishedMember(result, type, _umbracoContextAccessor).CreateModel();
});
}
public IPublishedContent GetByMember(IMember member)
{
var type = _contentTypeCache.Get(PublishedItemType.Member, member.ContentTypeId);
return new PublishedMember(member, type).CreateModel();
return new PublishedMember(member, type, _umbracoContextAccessor).CreateModel();
}
public XPathNavigator CreateNavigator()

View File

@@ -35,6 +35,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
private readonly IDefaultCultureAccessor _defaultCultureAccessor;
private readonly ISiteDomainHelper _siteDomainHelper;
private readonly IEntityXmlSerializer _entitySerializer;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
#region Constructors
@@ -44,6 +45,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
IScopeProvider scopeProvider,
IAppCache requestCache,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
IDefaultCultureAccessor defaultCultureAccessor,
ILogger logger,
@@ -52,12 +54,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
IEntityXmlSerializer entitySerializer,
MainDom mainDom,
bool testing = false, bool enableRepositoryEvents = true)
: this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache,
publishedSnapshotAccessor, variationContextAccessor,
: this(serviceContext, publishedContentTypeFactory, scopeProvider, requestCache,
publishedSnapshotAccessor, variationContextAccessor, umbracoContextAccessor,
documentRepository, mediaRepository, memberRepository,
defaultCultureAccessor,
logger, globalSettings, siteDomainHelper, entitySerializer, null, mainDom, testing, enableRepositoryEvents)
{ }
{
_umbracoContextAccessor = umbracoContextAccessor;
}
// used in some tests
internal PublishedSnapshotService(ServiceContext serviceContext,
@@ -65,6 +69,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
IScopeProvider scopeProvider,
IAppCache requestCache,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
IUmbracoContextAccessor umbracoContextAccessor,
IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository,
IDefaultCultureAccessor defaultCultureAccessor,
ILogger logger,
@@ -92,6 +97,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
_defaultCultureAccessor = defaultCultureAccessor;
_requestCache = requestCache;
_umbracoContextAccessor = umbracoContextAccessor;
_globalSettings = globalSettings;
_siteDomainHelper = siteDomainHelper;
_entitySerializer = entitySerializer;
@@ -138,9 +144,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var domainCache = new DomainCache(_domainService, _defaultCultureAccessor);
return new PublishedSnapshot(
new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _siteDomainHelper, _contentTypeCache, _routesCache, previewToken),
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache, _entitySerializer),
new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache),
new PublishedContentCache(_xmlStore, domainCache, _requestCache, _globalSettings, _siteDomainHelper,_umbracoContextAccessor, _contentTypeCache, _routesCache, previewToken),
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache, _entitySerializer, _umbracoContextAccessor),
new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache, _umbracoContextAccessor),
domainCache);
}

View File

@@ -20,21 +20,29 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
[XmlType(Namespace = "http://umbraco.org/webservices/")]
internal class XmlPublishedContent : PublishedContentBase
{
private XmlPublishedContent(XmlNode xmlNode, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache)
private XmlPublishedContent(
XmlNode xmlNode,
bool isPreviewing,
IAppCache appCache,
PublishedContentTypeCache contentTypeCache,
IUmbracoContextAccessor umbracoContextAccessor)
:base(umbracoContextAccessor)
{
_xmlNode = xmlNode;
_isPreviewing = isPreviewing;
_appCache = appCache;
_contentTypeCache = contentTypeCache;
_umbracoContextAccessor = umbracoContextAccessor;
}
private readonly XmlNode _xmlNode;
private readonly bool _isPreviewing;
private readonly IAppCache _appCache; // at snapshot/request level (see PublishedContentCache)
private readonly PublishedContentTypeCache _contentTypeCache;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly object _initializeLock = new object();
private readonly object _initializeLock = new object();
private bool _nodeInitialized;
private bool _parentInitialized;
@@ -252,7 +260,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
if (parent == null) return;
if (parent.Attributes?.GetNamedItem("isDoc") != null)
_parent = Get(parent, _isPreviewing, _appCache, _contentTypeCache);
_parent = Get(parent, _isPreviewing, _appCache, _contentTypeCache, _umbracoContextAccessor);
_parentInitialized = true;
}
@@ -409,7 +417,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var iterator = nav.Select(expr);
_children = iterator.Cast<XPathNavigator>()
.Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _appCache, _contentTypeCache))
.Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _appCache, _contentTypeCache, _umbracoContextAccessor))
.OrderBy(x => x.SortOrder)
.ToList();
@@ -423,11 +431,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
/// <param name="isPreviewing">A value indicating whether we are previewing or not.</param>
/// <param name="appCache">A cache.</param>
/// <param name="contentTypeCache">A content type cache.</param>
/// <param name="umbracoContextAccessor">A umbraco context accessor</param>
/// <returns>The IPublishedContent corresponding to the Xml cache node.</returns>
/// <remarks>Maintains a per-request cache of IPublishedContent items in order to make
/// sure that we create only one instance of each for the duration of a request. The
/// returned IPublishedContent is a model, if models are enabled.</remarks>
public static IPublishedContent Get(XmlNode node, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache)
public static IPublishedContent Get(XmlNode node, bool isPreviewing, IAppCache appCache,
PublishedContentTypeCache contentTypeCache, IUmbracoContextAccessor umbracoContextAccessor)
{
// only 1 per request
@@ -435,7 +445,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
var id = attrs?.GetNamedItem("id").Value;
if (id.IsNullOrWhiteSpace()) throw new InvalidOperationException("Node has no ID attribute.");
var key = CacheKeyPrefix + id; // dont bother with preview, wont change during request in Xml cache
return (IPublishedContent) appCache.Get(key, () => (new XmlPublishedContent(node, isPreviewing, appCache, contentTypeCache)).CreateModel());
return (IPublishedContent) appCache.Get(key, () => (new XmlPublishedContent(node, isPreviewing, appCache, contentTypeCache, umbracoContextAccessor)).CreateModel());
}
public static void ClearRequest()