Implemented an extension method to lessen duplication of code

This commit is contained in:
Zeegaan
2021-08-16 10:31:11 +02:00
parent 1906228ead
commit cca7c379ae
17 changed files with 46 additions and 106 deletions

View File

@@ -238,10 +238,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
get
{
var getById = GetGetterById();
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
{
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
}
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
return getById(publishedSnapshot, IsPreviewing, ParentId);
}
}
@@ -252,10 +249,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
get
{
var getById = GetGetterById();
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
{
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
}
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
var id = _contentNode.FirstChildContentId;
while (id > 0)
@@ -322,10 +316,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
// beware what you use that one for - you don't want to cache its result
private IAppCache GetAppropriateCache()
{
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
{
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
}
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
var cache = publishedSnapshot == null
? null
: ((IsPreviewing == false || PublishedSnapshotService.FullCacheWhenPreviewing) && (ContentType.ItemType != PublishedItemType.Member)
@@ -336,10 +327,7 @@ namespace Umbraco.Cms.Infrastructure.PublishedCache
private IAppCache GetCurrentSnapshotCache()
{
if (!_publishedSnapshotAccessor.TryGetPublishedSnapshot(out var publishedSnapshot))
{
throw new InvalidOperationException("Wasn't possible to a get a valid Snapshot");
}
var publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot();
return publishedSnapshot?.SnapshotCache;
}