Fix and cleanup

This commit is contained in:
Stephan
2019-06-07 11:15:58 +02:00
parent 7fd6bfa163
commit 14a056f4f4
24 changed files with 322 additions and 302 deletions

View File

@@ -1,20 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.XPath;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Services;
using Umbraco.Core.Xml;
using Umbraco.Core.Xml.XPath;
using Umbraco.Web.PublishedCache.NuCache.Navigable;
using Umbraco.Web.Routing;
namespace Umbraco.Web.PublishedCache.NuCache
{
@@ -25,6 +20,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
private readonly IAppCache _elementsCache;
private readonly IDomainCache _domainCache;
private readonly IGlobalSettings _globalSettings;
private readonly IVariationContextAccessor _variationContextAccessor;
#region Constructor
@@ -33,7 +29,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
// it's too late for UmbracoContext which has captured previewDefault and stuff into these ctor vars
// but, no, UmbracoContext returns snapshot.Content which comes from elements SO a resync should create a new cache
public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IGlobalSettings globalSettings)
public ContentCache(bool previewDefault, ContentStore.Snapshot snapshot, IAppCache snapshotCache, IAppCache elementsCache, IDomainCache domainCache, IGlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor)
: base(previewDefault)
{
_snapshot = snapshot;
@@ -41,6 +37,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
_elementsCache = elementsCache;
_domainCache = domainCache;
_globalSettings = globalSettings;
_variationContextAccessor = variationContextAccessor;
}
private bool HideTopLevelNodeFromPath => _globalSettings.HideTopLevelNodeFromPath;
@@ -241,7 +238,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
var guidUdi = contentId as GuidUdi;
if (guidUdi == null)
throw new ArgumentException($"Udi must be of type {typeof(GuidUdi).Name}.", nameof(contentId));
if (guidUdi.EntityType != Constants.UdiEntityType.Document)
throw new ArgumentException($"Udi entity type must be \"{Constants.UdiEntityType.Document}\".", nameof(contentId));
@@ -256,11 +253,18 @@ namespace Umbraco.Web.PublishedCache.NuCache
return preview || n.PublishedModel != null;
}
public override IEnumerable<IPublishedContent> GetAtRoot(bool preview)
IEnumerable<IPublishedContent> INavigableData.GetAtRoot(bool preview) => GetAtRoot(preview);
public override IEnumerable<IPublishedContent> GetAtRoot(bool preview, string culture = null)
{
// handle context culture for variant
if (culture == null)
culture = _variationContextAccessor?.VariationContext?.Culture ?? "";
// both .Draft and .Published cannot be null at the same time
// root is already sorted by sortOrder, and does not contain nulls
return _snapshot.GetAtRoot().Select(n => GetNodePublishedContent(n, preview));
var atRoot = _snapshot.GetAtRoot().Select(n => GetNodePublishedContent(n, preview));
return culture == "*" ? atRoot : atRoot.Where(x => x.IsInvariantOrHasCulture(culture));
}
private static IPublishedContent GetNodePublishedContent(ContentNode node, bool preview)