Refactor IPublishedContent.GetCultureFromDomains()

This commit is contained in:
Stephan
2019-04-17 14:41:54 +02:00
parent e062ea8d31
commit a996d46b6f
21 changed files with 153 additions and 114 deletions

View File

@@ -4,16 +4,23 @@ using Umbraco.Web.Routing;
namespace Umbraco.Web.PublishedCache.NuCache
{
/// <summary>
/// Implements <see cref="IDomainCache"/> for NuCache.
/// </summary>
internal class DomainCache : IDomainCache
{
private readonly SnapDictionary<int, Domain>.Snapshot _snapshot;
/// <summary>
/// Initializes a new instance of the <see cref="DomainCache"/> class.
/// </summary>
public DomainCache(SnapDictionary<int, Domain>.Snapshot snapshot, string defaultCulture)
{
_snapshot = snapshot;
DefaultCulture = defaultCulture; // capture - fast
DefaultCulture = defaultCulture;
}
/// <inheritdoc />
public IEnumerable<Domain> GetAll(bool includeWildcards)
{
var list = _snapshot.GetAll();
@@ -21,17 +28,23 @@ namespace Umbraco.Web.PublishedCache.NuCache
return list;
}
public IEnumerable<Domain> GetAssigned(int contentId, bool includeWildcards)
/// <inheritdoc />
public IEnumerable<Domain> GetAssigned(int documentId, bool includeWildcards = false)
{
// probably this could be optimized with an index
// but then we'd need a custom DomainStore of some sort
var list = _snapshot.GetAll();
list = list.Where(x => x.ContentId == contentId);
list = list.Where(x => x.ContentId == documentId);
if (includeWildcards == false) list = list.Where(x => x.IsWildcard == false);
return list;
}
/// <inheritdoc />
public bool HasAssigned(int documentId, bool includeWildcards = false)
=> documentId > 0 && GetAssigned(documentId, includeWildcards).Any();
/// <inheritdoc />
public string DefaultCulture { get; }
}
}