diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs
index 5f3a51f4f6..0dcc4bea99 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs
@@ -195,7 +195,7 @@ namespace Umbraco.Tests.PublishedContent
[Test]
public void PublishedContentQueryTypedContentList()
{
- var query = new PublishedContentQuery(UmbracoContext.Current.ContentCache, UmbracoContext.Current.MediaCache, UmbracoContext.Current.VariationContextAccessor);
+ var query = new PublishedContentQuery(UmbracoContext.Current.PublishedSnapshot, UmbracoContext.Current.VariationContextAccessor);
var result = query.Content(new[] { 1, 2, 4 }).ToArray();
Assert.AreEqual(2, result.Length);
Assert.AreEqual(1, result[0].Id);
diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs
index 2c4d08502e..61180580cb 100644
--- a/src/Umbraco.Web/PublishedContentQuery.cs
+++ b/src/Umbraco.Web/PublishedContentQuery.cs
@@ -2,41 +2,31 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
-using System.Reflection;
-using System.Text.RegularExpressions;
using System.Xml.XPath;
using Examine;
using Examine.Search;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
-using Umbraco.Core.Services;
using Umbraco.Core.Xml;
using Umbraco.Examine;
using Umbraco.Web.PublishedCache;
namespace Umbraco.Web
{
- using Examine = global::Examine;
-
///
/// A class used to query for published content, media items
///
public class PublishedContentQuery : IPublishedContentQuery
{
- private readonly IPublishedContentCache _contentCache;
- private readonly IPublishedMediaCache _mediaCache;
+ private readonly IPublishedSnapshot _publishedSnapshot;
private readonly IVariationContextAccessor _variationContextAccessor;
///
- /// Constructor used to return results from the caches
+ /// Initializes a new instance of the class.
///
- ///
- ///
- ///
- public PublishedContentQuery(IPublishedContentCache contentCache, IPublishedMediaCache mediaCache, IVariationContextAccessor variationContextAccessor)
+ public PublishedContentQuery(IPublishedSnapshot publishedSnapshot, IVariationContextAccessor variationContextAccessor)
{
- _contentCache = contentCache ?? throw new ArgumentNullException(nameof(contentCache));
- _mediaCache = mediaCache ?? throw new ArgumentNullException(nameof(mediaCache));
+ _publishedSnapshot = publishedSnapshot ?? throw new ArgumentNullException(nameof(publishedSnapshot));
_variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
}
@@ -44,48 +34,48 @@ namespace Umbraco.Web
public IPublishedContent Content(int id)
{
- return ItemById(id, _contentCache);
+ return ItemById(id, _publishedSnapshot.Content);
}
public IPublishedContent Content(Guid id)
{
- return ItemById(id, _contentCache);
+ return ItemById(id, _publishedSnapshot.Content);
}
public IPublishedContent Content(Udi id)
{
if (!(id is GuidUdi udi)) return null;
- return ItemById(udi.Guid, _contentCache);
+ return ItemById(udi.Guid, _publishedSnapshot.Content);
}
public IPublishedContent ContentSingleAtXPath(string xpath, params XPathVariable[] vars)
{
- return ItemByXPath(xpath, vars, _contentCache);
+ return ItemByXPath(xpath, vars, _publishedSnapshot.Content);
}
public IEnumerable Content(IEnumerable ids)
{
- return ItemsByIds(_contentCache, ids);
+ return ItemsByIds(_publishedSnapshot.Content, ids);
}
public IEnumerable Content(IEnumerable ids)
{
- return ItemsByIds(_contentCache, ids);
+ return ItemsByIds(_publishedSnapshot.Content, ids);
}
public IEnumerable ContentAtXPath(string xpath, params XPathVariable[] vars)
{
- return ItemsByXPath(xpath, vars, _contentCache);
+ return ItemsByXPath(xpath, vars, _publishedSnapshot.Content);
}
public IEnumerable ContentAtXPath(XPathExpression xpath, params XPathVariable[] vars)
{
- return ItemsByXPath(xpath, vars, _contentCache);
+ return ItemsByXPath(xpath, vars, _publishedSnapshot.Content);
}
public IEnumerable ContentAtRoot()
{
- return ItemsAtRoot(_contentCache);
+ return ItemsAtRoot(_publishedSnapshot.Content);
}
#endregion
@@ -94,33 +84,33 @@ namespace Umbraco.Web
public IPublishedContent Media(int id)
{
- return ItemById(id, _mediaCache);
+ return ItemById(id, _publishedSnapshot.Media);
}
public IPublishedContent Media(Guid id)
{
- return ItemById(id, _mediaCache);
+ return ItemById(id, _publishedSnapshot.Media);
}
public IPublishedContent Media(Udi id)
{
if (!(id is GuidUdi udi)) return null;
- return ItemById(udi.Guid, _mediaCache);
+ return ItemById(udi.Guid, _publishedSnapshot.Media);
}
public IEnumerable Media(IEnumerable ids)
{
- return ItemsByIds(_mediaCache, ids);
+ return ItemsByIds(_publishedSnapshot.Media, ids);
}
public IEnumerable Media(IEnumerable ids)
{
- return ItemsByIds(_mediaCache, ids);
+ return ItemsByIds(_publishedSnapshot.Media, ids);
}
public IEnumerable MediaAtRoot()
{
- return ItemsAtRoot(_mediaCache);
+ return ItemsAtRoot(_publishedSnapshot.Media);
}
@@ -224,7 +214,7 @@ namespace Umbraco.Web
totalRecords = results.TotalItemCount;
- return new CultureContextualSearchResults(results.ToPublishedSearchResults(_contentCache), _variationContextAccessor, culture);
+ return new CultureContextualSearchResults(results.ToPublishedSearchResults(_publishedSnapshot.Content), _variationContextAccessor, culture);
}
///
@@ -241,7 +231,7 @@ namespace Umbraco.Web
: query.Execute(maxResults: skip + take);
totalRecords = results.TotalItemCount;
- return results.ToPublishedSearchResults(_contentCache);
+ return results.ToPublishedSearchResults(_publishedSnapshot.Content);
}
///
diff --git a/src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs b/src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs
index 382ee6fe12..e3cad25c6f 100644
--- a/src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs
+++ b/src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs
@@ -13,7 +13,6 @@ namespace Umbraco.Web.Routing
///
public class ContentFinderByConfigured404 : IContentLastChanceFinder
{
-
private readonly ILogger _logger;
private readonly IEntityService _entityService;
private readonly IContentSection _contentConfigSection;
@@ -63,7 +62,7 @@ namespace Umbraco.Web.Routing
var error404 = NotFoundHandlerHelper.GetCurrentNotFoundPageId(
_contentConfigSection.Error404Collection.ToArray(),
_entityService,
- new PublishedContentQuery(frequest.UmbracoContext.ContentCache, frequest.UmbracoContext.MediaCache, frequest.UmbracoContext.VariationContextAccessor),
+ new PublishedContentQuery(frequest.UmbracoContext.PublishedSnapshot, frequest.UmbracoContext.VariationContextAccessor),
errorCulture);
IPublishedContent content = null;
diff --git a/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs b/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs
index 0f17c19bdb..3afe6aa397 100644
--- a/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs
+++ b/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs
@@ -91,7 +91,7 @@ namespace Umbraco.Web.Runtime
composition.Register(factory =>
{
var umbCtx = factory.GetInstance();
- return new PublishedContentQuery(umbCtx.UmbracoContext.ContentCache, umbCtx.UmbracoContext.MediaCache, factory.GetInstance());
+ return new PublishedContentQuery(umbCtx.UmbracoContext.PublishedSnapshot, factory.GetInstance());
}, Lifetime.Request);
composition.Register(Lifetime.Request);
diff --git a/src/Umbraco.Web/UmbracoHelper.cs b/src/Umbraco.Web/UmbracoHelper.cs
index 962d181d7b..d2da4d1646 100644
--- a/src/Umbraco.Web/UmbracoHelper.cs
+++ b/src/Umbraco.Web/UmbracoHelper.cs
@@ -73,7 +73,7 @@ namespace Umbraco.Web
#endregion
// ensures that we can return the specified value
- T Ensure(T o) where T : class => o ?? throw new InvalidOperationException(""); // fixme
+ T Ensure(T o) where T : class => o ?? throw new InvalidOperationException("This UmbracoHelper instance has not been initialized.");
private IUmbracoComponentRenderer ComponentRenderer => Ensure(_componentRenderer);
private ICultureDictionaryFactory CultureDictionaryFactory => Ensure(_cultureDictionaryFactory);