2

I'm trying to make a parent page get reindexed when a certain child item updates via the Indexing.GetDependencies pipeline. So far it's picking up the target child item fine, but it then goes into a loop of believing the child item has been updated again and never tries to update the dependent item. Any idea what might be putting it into the update loop?

public class IndexEventOnDateUpdate : BaseProcessor
    {

        public override void Process(GetDependenciesArgs args)
        {
            Assert.IsNotNull(args.IndexedItem, "indexed item");
            Assert.IsNotNull(args.Dependencies, "dependencies");
            Item item = args.IndexedItem as SitecoreIndexableItem;
            var realitem = item?.AsStronglyTyped();
            if (realitem != null && (realitem is IBaseEventDetailDateItem || realitem is IBaseEventDetailDateOverrideItem))
            {
                Item parent = item.Axes.GetAncestors().FirstOrDefault(x => x.TemplateName == "Event Page");
                if (parent != null) args.Dependencies.Add(new IndexableUniqueId<string>(parent.GetUniqueId()));
            }
        }
    }
3
  • What version of Sitecore? Also, is it possible that a parent item refers to a child item as a datasource in its presentation? If you know exactly the items where this is happening, then please past the item ids of parent and child, together with the content of the presenation (use view raw details). Dec 2, 2023 at 16:23
  • Can you check the showconfig to see if any other processors are enabled in the getdependencies pipeline? How many languages/versions does your test item have?
    – Gatogordo
    Dec 4, 2023 at 8:44
  • Currently running 10.1 with an imminent upgrade to 10.3, I did just realize I forgot to look further down the pipeline, and I think indexing.getChildrenToIndex is the source of my grief. Going to explore it now.
    – Matt K.
    Dec 4, 2023 at 15:00

1 Answer 1

2

The issue you're experiencing might be related to how the GetDependencies pipeline works. When adding dependencies, it's crucial to ensure that you don't inadvertently create a circular dependency or trigger unnecessary updates.

Here are a few suggestions to avoid the update loop:

Check for Existing Dependencies: Before adding a dependency, check if it's not already present in the args.Dependencies collection. If it's already there, avoid adding it again to prevent a loop.

 if (parent != null && !args.Dependencies.Contains(new IndexableUniqueId<string>(parent.GetUniqueId())))
{
    args.Dependencies.Add(new IndexableUniqueId<string>(parent.GetUniqueId()));
}

Ensure Dependencies are Unique: Confirm that the unique identifiers used for dependencies are unique and consistent. If there's any inconsistency, it might result in the pipeline incorrectly detecting a change in the child item repeatedly.

Avoid Adding the Same Item as Dependency: Check if the indexedItem is the same as the parent. If they are the same, it's unnecessary to add it as a dependency, as it could lead to a circular dependency.

if (parent != null && !item.ID.Equals(parent.ID) && !args.Dependencies.Contains(new IndexableUniqueId<string>(parent.GetUniqueId())))
{
    args.Dependencies.Add(new IndexableUniqueId<string>(parent.GetUniqueId()));
}

Debugging: Introduce logging or debugging statements to track the flow of the GetDependencies pipeline. This can help identify if there's an unexpected condition causing the loop.

Log.Info($"Processing item {item.ID} in GetDependencies pipeline.", this);

Review Parent Item Changes: Ensure that updates to the parent item are appropriately triggering the GetDependencies pipeline without leading to a circular update.

By implementing these suggestions, you can enhance the reliability of your GetDependencies pipeline and prevent unnecessary update loops.

3
  • 1
    Thanks. Finally have time to debug this again and I'm starting to see a possible pattern. In this case there may be more than one child of the type I want to trigger the parent's reindex. If they both get triggered they could both be adding the parent again as a dependency and off we go. However this logic is breaking down upon further debugging.
    – Matt K.
    Dec 20, 2023 at 16:33
  • 1
    SUCCESS! So it turns out I wasn't in an infinite index loop as much as when the crawler tried to process the dependencies of the child item the parent's unique ID wouldn't parse correctly. This caused the crawler to fail, but once it recovered it noticed that the child item still needed indexing setting off the whole chain again. I fiddled around inspecting the crawler code where it errored (Sitecore's standard crawler BTW) and changed the code to build the dependency using the parent's ItemURI instead of the UniqueID. This fixed it, and the index is now updating cleanly when child updates!
    – Matt K.
    Dec 21, 2023 at 10:20
  • Fantastic! @MattK. Dec 22, 2023 at 4:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.