From 9b4b8b9d868c5f33c9034185c4018cb89ee75cb7 Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 28 Jan 2019 14:15:47 +0100 Subject: [PATCH] Cleanup NuCache/PublishedContent --- .../PublishedCache/NuCache/ContentCache.cs | 8 ++-- .../PublishedCache/NuCache/ContentNode.cs | 39 +++++++++++-------- .../PublishedCache/NuCache/ContentStore.cs | 2 +- .../PublishedCache/NuCache/MediaCache.cs | 6 +-- .../NuCache/PublishedContent.cs | 4 +- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs b/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs index cab6e7d759..74cf960170 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/ContentCache.cs @@ -243,7 +243,7 @@ namespace Umbraco.Web.PublishedCache.NuCache var n = _snapshot.Get(contentId); if (n == null) return false; - return preview || n.Published != null; + return preview || n.PublishedModel != null; } public override IEnumerable GetAtRoot(bool preview) @@ -280,8 +280,8 @@ namespace Umbraco.Web.PublishedCache.NuCache // both .Draft and .Published cannot be null at the same time return preview - ? node.Draft ?? GetPublishedContentAsDraft(node.Published) - : node.Published; + ? node.DraftModel ?? GetPublishedContentAsDraft(node.PublishedModel) + : node.PublishedModel; } // gets a published content as a previewing draft, if preview is true @@ -302,7 +302,7 @@ namespace Umbraco.Web.PublishedCache.NuCache { return preview ? _snapshot.IsEmpty == false - : _snapshot.GetAtRoot().Any(x => x.Published != null); + : _snapshot.GetAtRoot().Any(x => x.PublishedModel != null); } #endregion diff --git a/src/Umbraco.Web/PublishedCache/NuCache/ContentNode.cs b/src/Umbraco.Web/PublishedCache/NuCache/ContentNode.cs index 647adaad91..4ce6021801 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/ContentNode.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/ContentNode.cs @@ -67,9 +67,9 @@ 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(); + DraftModel = new PublishedContent(this, draftData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); if (publishedData != null) - Published = new PublishedContent(this, publishedData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); + PublishedModel = new PublishedContent(this, publishedData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); } // clone parent @@ -88,11 +88,11 @@ namespace Umbraco.Web.PublishedCache.NuCache CreateDate = origin.CreateDate; CreatorId = origin.CreatorId; - var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft); - var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published); + var originDraft = origin.DraftModel == null ? null : PublishedContent.UnwrapIPublishedContent(origin.DraftModel); + var originPublished = origin.PublishedModel == null ? null : PublishedContent.UnwrapIPublishedContent(origin.PublishedModel); - Draft = originDraft == null ? null : new PublishedContent(this, originDraft).CreateModel(); - Published = originPublished == null ? null : new PublishedContent(this, originPublished).CreateModel(); + DraftModel = originDraft == null ? null : new PublishedContent(this, originDraft).CreateModel(); + PublishedModel = originPublished == null ? null : new PublishedContent(this, originPublished).CreateModel(); ChildContentIds = new List(origin.ChildContentIds); // needs to be *another* list } @@ -110,11 +110,13 @@ namespace Umbraco.Web.PublishedCache.NuCache CreateDate = origin.CreateDate; CreatorId = origin.CreatorId; - var originDraft = origin.Draft == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Draft); - var originPublished = origin.Published == null ? null : PublishedContent.UnwrapIPublishedContent(origin.Published); + var originDraft = origin.DraftModel == null ? null : PublishedContent.UnwrapIPublishedContent(origin.DraftModel); + var originPublished = origin.PublishedModel == null ? null : PublishedContent.UnwrapIPublishedContent(origin.PublishedModel); - Draft = originDraft == null ? null : new PublishedContent(this, originDraft._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); - Published = originPublished == null ? null : new PublishedContent(this, originPublished._contentData, publishedSnapshotAccessor, variationContextAccessor).CreateModel(); + DraftContent = originDraft == null ? null : new PublishedContent(this, originDraft._contentData, publishedSnapshotAccessor, variationContextAccessor); + DraftModel = DraftContent?.CreateModel(); + PublishedContent = originPublished == null ? null : new PublishedContent(this, originPublished._contentData, publishedSnapshotAccessor, variationContextAccessor); + PublishedModel = PublishedContent?.CreateModel(); ChildContentIds = origin.ChildContentIds; // can be the *same* list } @@ -132,10 +134,15 @@ namespace Umbraco.Web.PublishedCache.NuCache public readonly DateTime CreateDate; public readonly int CreatorId; + // draft and published version (either can be null, but not both) + // are the direct PublishedContent instances + public PublishedContent DraftContent; + public PublishedContent PublishedContent; + // draft and published version (either can be null, but not both) // are models not direct PublishedContent instances - public IPublishedContent Draft; - public IPublishedContent Published; + public IPublishedContent DraftModel; + public IPublishedContent PublishedModel; public ContentNode CloneParent(IPublishedSnapshotAccessor publishedSnapshotAccessor) { @@ -144,13 +151,13 @@ namespace Umbraco.Web.PublishedCache.NuCache public ContentNodeKit ToKit() { - var draft = Draft is PublishedContentModel draftModel + var draft = DraftModel is PublishedContentModel draftModel ? (PublishedContent) draftModel.Unwrap() - : (PublishedContent) Draft; + : (PublishedContent) DraftModel; - var published = Published is PublishedContentModel publishedModel + var published = PublishedModel is PublishedContentModel publishedModel ? (PublishedContent) publishedModel.Unwrap() - : (PublishedContent) Published; + : (PublishedContent) PublishedModel; return new ContentNodeKit { diff --git a/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs b/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs index 353ac83eda..b14a8041bd 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs @@ -652,7 +652,7 @@ namespace Umbraco.Web.PublishedCache.NuCache return true; var link = GetParentLink(kit.Node); var node = link?.Value; - return node?.Published != null; + return node?.PublishedModel != null; } private void AddToParentLocked(ContentNode content) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/MediaCache.cs b/src/Umbraco.Web/PublishedCache/NuCache/MediaCache.cs index 28c7c38c36..7a22366165 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/MediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/MediaCache.cs @@ -34,14 +34,14 @@ namespace Umbraco.Web.PublishedCache.NuCache { // ignore preview, there's only draft for media var n = _snapshot.Get(contentId); - return n?.Published; + return n?.PublishedModel; } public override IPublishedContent GetById(bool preview, Guid contentId) { // ignore preview, there's only draft for media var n = _snapshot.Get(contentId); - return n?.Published; + return n?.PublishedModel; } public override bool HasById(bool preview, int contentId) @@ -73,7 +73,7 @@ namespace Umbraco.Web.PublishedCache.NuCache var c = _snapshot.GetAtRoot(); // ignore preview, there's only draft for media - return c.Select(n => n.Published); + return c.Select(n => n.PublishedModel); } public override bool HasContent(bool preview) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs index ced655ab43..b9d74e7f15 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs @@ -300,7 +300,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // invariant content items) // if there is no 'published' published content, no culture can be published - var hasPublished = _contentNode.Published != null; + var hasPublished = _contentNode.PublishedModel != null; if (!hasPublished) return false; @@ -314,7 +314,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // there is a 'published' published content, and varies // = depends on the culture - return ((PublishedContent) _contentNode.Published)._contentData.CultureInfos.ContainsKey(culture); + return _contentNode.PublishedContent._contentData.CultureInfos.ContainsKey(culture); } #endregion