Delivery API: Fix not reindexing branch descendants when branch root already published but unchanged (closes #20370) (#20462)

* Fix deliveryApi not reindexing branch descendants when branch root already published and unchanged

* Commit update and name improvement
This commit is contained in:
Sven Geusens
2025-10-14 01:15:01 -09:00
committed by Sven Geusens
parent 7f1cdf8ef5
commit 49f3fc9993

View File

@@ -59,7 +59,19 @@ internal sealed class DeliveryApiContentIndexHandleContentChanges : DeliveryApiC
RemoveFromIndex(pendingRemovals, index);
pendingRemovals.Clear();
Reindex(content, index);
ReIndexResult reIndexResult = Reindex(content, index);
// When we get to this point, we are dealing with either
// a refresh node or a refresh branch (see reindex =...).
// A refresh branch can be many things, the Reindex function takes care of most scenarios.
// But it only reindexes descendants if the base node has any changed cultures (see comments in that function)
// So by checking what kind of operation it did when the initial indexrequest is for a refresh branch,
// we can support reindexing a branch while the base node was unchanged.
if (reIndexResult == ReIndexResult.Updated && changeTypes.HasType(TreeChangeTypes.RefreshBranch))
{
ReindexDescendants(content, index);
}
}
}
@@ -68,7 +80,7 @@ internal sealed class DeliveryApiContentIndexHandleContentChanges : DeliveryApiC
return Task.CompletedTask;
});
private void Reindex(IContent content, IIndex index)
private ReIndexResult Reindex(IContent content, IIndex index)
{
// get the currently indexed cultures for the content
CulturePublishStatus[] existingCultures = index
@@ -95,16 +107,19 @@ internal sealed class DeliveryApiContentIndexHandleContentChanges : DeliveryApiC
// we likely got here because a removal triggered a "refresh branch" notification, now we
// need to delete every last culture of this content and all descendants
RemoveFromIndex(content.Id, index);
return;
return ReIndexResult.Removed;
}
// if the published state changed of any culture, chances are there are similar changes ot the content descendants
// if the published state changed of any culture, chances are there are similar changes at the content descendants
// that need to be reflected in the index, so we'll reindex all descendants
var changedCulturePublishStatus = indexedCultures.Intersect(existingCultures).Count() != existingCultures.Length;
if (changedCulturePublishStatus)
{
ReindexDescendants(content, index);
return ReIndexResult.UpdatedWithDescendants;
}
return ReIndexResult.Updated;
}
private CulturePublishStatus[] UpdateIndex(IContent content, IIndex index)
@@ -179,4 +194,11 @@ internal sealed class DeliveryApiContentIndexHandleContentChanges : DeliveryApiC
public override int GetHashCode() => HashCode.Combine(Culture, Published);
}
private enum ReIndexResult
{
Updated,
UpdatedWithDescendants,
Removed,
}
}