How to know what pages have changed when related content is published

I have an interresting challenge. For some custom indexing (this is completely seperate from any Umbraco indexing) I need to inform an external system when pages have been published or depublished. I think I might use the webhooks for that, but that’s not relevant for the question.

The thing is, we sometimes have ‘shared’ or ‘reusable’ content. For instance, a list of quotes, a list of FAQ elements or a list of locations with addresses. On certain nodes, these reusable content elements can be picked, so they don’t need to be created for each page individually and can be reused. It also makes it easier to update that reusable content in one single location.

When the content of a reusable element gets updated, from the perspective of Umbraco, it’s just a node that gets updated. However, from a frontend perspective, the content of multiple pages actually changes because that reusable content is displayed on all these pages. So for the index, I need a list of all pages that are updated, not just the node that was updated. But I’m not sure how I can easily know what pages have a reusable element picked that was just published.. Any ideas?

Could you use umbraco relations in a publishedNotification Handler?
As you’d get a prompt when trying to delete the reused content that it was in use on the page.. so it’s already linked for you?

@using cnv = Umbraco.Cms.Core.Constants.Conventions
@inject IRelationService _relationService

    var relations = _relationService.GetByChildId({reusableNodeId}, cnv.RelationTypes.RelatedDocumentAlias);
    foreach (var relation in relations)
    {
        var parent = relation.ParentId;
    }

Yeah I was also thinking in that direction. I know relations exist, but I never really understood the feature and what does and doesn’t get stored as relation, but it certainly is worth a look!