Merge pull request #5240 from umbraco/v8/bugfix/5222-nucache-vanishing-content

NuCache: fix vanishing content when refreshing content types
This commit is contained in:
Shannon Deminick
2019-04-15 12:55:43 +10:00
committed by GitHub

View File

@@ -313,6 +313,8 @@ namespace Umbraco.Web.PublishedCache.NuCache
var removedContentTypeNodes = new List<int>(); var removedContentTypeNodes = new List<int>();
var refreshedContentTypeNodes = new List<int>(); var refreshedContentTypeNodes = new List<int>();
// find all the nodes that are either refreshed or removed,
// because of their content type being either refreshed or removed
foreach (var link in _contentNodes.Values) foreach (var link in _contentNodes.Values)
{ {
var node = link.Value; var node = link.Value;
@@ -322,39 +324,49 @@ namespace Umbraco.Web.PublishedCache.NuCache
if (refreshedIdsA.Contains(contentTypeId)) refreshedContentTypeNodes.Add(node.Id); if (refreshedIdsA.Contains(contentTypeId)) refreshedContentTypeNodes.Add(node.Id);
} }
// all content should have been deleted - but // perform deletion of content with removed content type
// removing content types should have removed their content already
// but just to be 100% sure, clear again here
foreach (var node in removedContentTypeNodes) foreach (var node in removedContentTypeNodes)
ClearBranchLocked(node); ClearBranchLocked(node);
// perform deletion of removed content types
foreach (var id in removedIdsA) foreach (var id in removedIdsA)
{ {
if (_contentTypesById.TryGetValue(id, out LinkedNode<PublishedContentType> link) == false || link.Value == null) if (_contentTypesById.TryGetValue(id, out var link) == false || link.Value == null)
continue; continue;
SetValueLocked(_contentTypesById, id, null); SetValueLocked(_contentTypesById, id, null);
SetValueLocked(_contentTypesByAlias, link.Value.Alias, null); SetValueLocked(_contentTypesByAlias, link.Value.Alias, null);
} }
// perform update of refreshed content types
foreach (var type in refreshedTypesA) foreach (var type in refreshedTypesA)
{ {
SetValueLocked(_contentTypesById, type.Id, type); SetValueLocked(_contentTypesById, type.Id, type);
SetValueLocked(_contentTypesByAlias, type.Alias, type); SetValueLocked(_contentTypesByAlias, type.Alias, type);
} }
// skip missing type // perform update of content with refreshed content type - from the kits
// skip missing parents & unbuildable kits - what else could we do? // skip missing type, skip missing parents & unbuildable kits - what else could we do?
// kits are ordered by level, so ParentExits is ok here
var visited = new List<int>(); var visited = new List<int>();
foreach (var kit in kits.Where(x => foreach (var kit in kits.Where(x =>
refreshedIdsA.Contains(x.ContentTypeId) && refreshedIdsA.Contains(x.ContentTypeId) &&
ParentExistsLocked(x) && ParentExistsLocked(x) &&
BuildKit(x))) BuildKit(x)))
{ {
// replacing the node: must preserve the parents
var node = GetHead(_contentNodes, kit.Node.Id)?.Value;
if (node != null)
kit.Node.ChildContentIds = node.ChildContentIds;
SetValueLocked(_contentNodes, kit.Node.Id, kit.Node); SetValueLocked(_contentNodes, kit.Node.Id, kit.Node);
visited.Add(kit.Node.Id); visited.Add(kit.Node.Id);
if (_localDb != null) RegisterChange(kit.Node.Id, kit); if (_localDb != null) RegisterChange(kit.Node.Id, kit);
} }
// all content should have been refreshed - but... // all content should have been refreshed - but...
var orphans = refreshedContentTypeNodes.Except(visited); var orphans = refreshedContentTypeNodes.Except(visited);
foreach (var id in orphans) foreach (var id in orphans)
ClearBranchLocked(id); ClearBranchLocked(id);