Merge branch temp8 into temp8-di2690
This commit is contained in:
@@ -198,6 +198,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
|
||||
private void InitializeRepositoryEvents()
|
||||
{
|
||||
//fixme: The reason these events are in the repository is for legacy, the events should exist at the service
|
||||
// level now since we can fire these events within the transaction... so move the events to service level
|
||||
|
||||
// plug repository event handlers
|
||||
// these trigger within the transaction to ensure consistency
|
||||
// and are used to maintain the central, database-level XML cache
|
||||
@@ -212,9 +215,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
MemberRepository.ScopedEntityRefresh += OnMemberRefreshedEntity;
|
||||
|
||||
// plug
|
||||
ContentTypeService.UowRefreshedEntity += OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.UowRefreshedEntity += OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.UowRefreshedEntity += OnMemberTypeRefreshedEntity;
|
||||
ContentTypeService.ScopedRefreshedEntity += OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.ScopedRefreshedEntity += OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.ScopedRefreshedEntity += OnMemberTypeRefreshedEntity;
|
||||
}
|
||||
|
||||
private void TearDownRepositoryEvents()
|
||||
@@ -229,9 +232,9 @@ namespace Umbraco.Web.PublishedCache.NuCache
|
||||
//MemberRepository.RemovedVersion -= OnMemberRemovedVersion;
|
||||
MemberRepository.ScopedEntityRefresh -= OnMemberRefreshedEntity;
|
||||
|
||||
ContentTypeService.UowRefreshedEntity -= OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.UowRefreshedEntity -= OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.UowRefreshedEntity -= OnMemberTypeRefreshedEntity;
|
||||
ContentTypeService.ScopedRefreshedEntity -= OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.ScopedRefreshedEntity -= OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.ScopedRefreshedEntity -= OnMemberTypeRefreshedEntity;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
private readonly ICacheProvider _cacheProvider; // at snapshot/request level (see PublishedContentCache)
|
||||
private readonly PublishedContentTypeCache _contentTypeCache;
|
||||
|
||||
private readonly object _initializeLock = new object();
|
||||
|
||||
private bool _nodeInitialized;
|
||||
private bool _parentInitialized;
|
||||
private bool _childrenInitialized;
|
||||
@@ -66,15 +68,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
if (_childrenInitialized == false) InitializeChildren();
|
||||
EnsureNodeInitialized(andChildren: true);
|
||||
return _children;
|
||||
}
|
||||
}
|
||||
|
||||
public override IPublishedProperty GetProperty(string alias)
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
IPublishedProperty property;
|
||||
return _properties.TryGetValue(alias, out property) ? property : null;
|
||||
}
|
||||
@@ -85,8 +86,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
if (_parentInitialized == false) InitializeParent();
|
||||
EnsureNodeInitialized(andParent: true);
|
||||
return _parent;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _id;
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _key;
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _template;
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _sortOrder;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _writerName;
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _creatorName;
|
||||
}
|
||||
}
|
||||
@@ -162,7 +162,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _writerId;
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _creatorId;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _path;
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _createDate;
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _updateDate;
|
||||
}
|
||||
}
|
||||
@@ -207,7 +207,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _urlName;
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _level;
|
||||
}
|
||||
}
|
||||
@@ -225,7 +225,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _isDraft;
|
||||
}
|
||||
}
|
||||
@@ -234,7 +234,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _properties.Values;
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
EnsureNodeInitialized();
|
||||
return _contentType;
|
||||
}
|
||||
}
|
||||
@@ -256,10 +256,27 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
if (parent.Attributes?.GetNamedItem("isDoc") != null)
|
||||
_parent = Get(parent, _isPreviewing, _cacheProvider, _contentTypeCache);
|
||||
|
||||
// warn: this is not thread-safe...
|
||||
_parentInitialized = true;
|
||||
}
|
||||
|
||||
private void EnsureNodeInitialized(bool andChildren = false, bool andParent = false)
|
||||
{
|
||||
// In *theory* XmlPublishedContent are a per-request thing, and so should not
|
||||
// end up being involved into multi-threaded situations - however, it's been
|
||||
// reported that some users ended up seeing 100% CPU due to infinite loops in
|
||||
// the properties dictionary in InitializeNode, which would indicate that the
|
||||
// dictionary *is* indeed involved in some multi-threaded operation. No idea
|
||||
// what users are doing that cause this, but let's be friendly and use a true
|
||||
// lock around initialization.
|
||||
|
||||
lock (_initializeLock)
|
||||
{
|
||||
if (_nodeInitialized == false) InitializeNode();
|
||||
if (andChildren && _childrenInitialized == false) InitializeChildren();
|
||||
if (andParent && _parentInitialized == false) InitializeParent();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeNode()
|
||||
{
|
||||
InitializeNode(this, _xmlNode, _isPreviewing,
|
||||
@@ -268,10 +285,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
out _createDate, out _updateDate, out _level, out _isDraft, out _contentType, out _properties,
|
||||
_contentTypeCache.Get);
|
||||
|
||||
// warn: this is not thread-safe...
|
||||
_nodeInitialized = true;
|
||||
}
|
||||
|
||||
// internal for some benchmarks
|
||||
internal static void InitializeNode(XmlPublishedContent node, XmlNode xmlNode, bool isPreviewing,
|
||||
out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
|
||||
out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
|
||||
@@ -398,7 +415,6 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
.OrderBy(x => x.SortOrder)
|
||||
.ToList();
|
||||
|
||||
// warn: this is not thread-safe
|
||||
_childrenInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -194,9 +194,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
MemberRepository.ScopedEntityRefresh += OnMemberRefreshedEntity;
|
||||
|
||||
// plug
|
||||
ContentTypeService.UowRefreshedEntity += OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.UowRefreshedEntity += OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.UowRefreshedEntity += OnMemberTypeRefreshedEntity;
|
||||
ContentTypeService.ScopedRefreshedEntity += OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.ScopedRefreshedEntity += OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.ScopedRefreshedEntity += OnMemberTypeRefreshedEntity;
|
||||
|
||||
_withRepositoryEvents = true;
|
||||
}
|
||||
@@ -213,9 +213,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
MemberRepository.ScopeVersionRemove -= OnMemberRemovingVersion;
|
||||
MemberRepository.ScopedEntityRefresh -= OnMemberRefreshedEntity;
|
||||
|
||||
ContentTypeService.UowRefreshedEntity -= OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.UowRefreshedEntity -= OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.UowRefreshedEntity -= OnMemberTypeRefreshedEntity;
|
||||
ContentTypeService.ScopedRefreshedEntity -= OnContentTypeRefreshedEntity;
|
||||
MediaTypeService.ScopedRefreshedEntity -= OnMediaTypeRefreshedEntity;
|
||||
MemberTypeService.ScopedRefreshedEntity -= OnMemberTypeRefreshedEntity;
|
||||
|
||||
_withRepositoryEvents = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user