Introduction

Starting a greenfield project on the Sitecore platform, I was always thinking that it would be a technically good solution. But then short terms, no time for knowledge sharing and mentorship, legacy code and content migration as is, etc., happened. And in a year or less, you have a big tech dept that slows down the development and sometimes even blocks DEVs and QAs from doing their work. And this topic is about one of such cases.

The issue

The big number of items (tens of thousands of items under /sitecore/content) that are tightly coupled and in many languages.

For my case, the one item publishing with the “related items” option found more than 40000 “related” items. It spent much more time on items finding than then on the process of publishing (for smart publishing). As a result, publishing of the bunch of items was blocking the publishing queue for hours (or until app restart).

The best solution is to revise the content structure and dependencies to find issues with references. But in our case, we have legacy content that we couldn’t change.

From the other perspective, for example, generic link field type is designed for hyperlinks, and the linking with it doesn’t make items related.

Implementation

By default, Sitecore.Publishing.Pipelines.GetItemReferences.AddItemLinkReferences has only one parameter (deepScan) - you can only decide to scan either everything or nothing.

I adjusted it to add more options for configuration.

  • skipDeepScanByFieldType ignores the links, that are located in the fields of the specified types.
  • onlyDeepScanByPaths argument ignores all items located not in the specific folders. On the production environment, the templates, renderings, etc., are deployed using CI/CD pipeline, and content editors are not supposed to make changes on these items.
  • skipDeepScanTemplates ignores items of the specific templates.
  • maxDepthDeepScan doesn’t allow to go very deep during related items resolving.

The configuration example.

<getItemReferences>
  <processor type="Demo.AddItemLinkReferencesExt, Demo" 
             patch:instead="processor[@type='Sitecore.Publishing.Pipelines.GetItemReferences.AddItemLinkReferences, Sitecore.Kernel']">
    <deepScan>true</deepScan>
    <skipDeepScanByFieldType hint="list">
      <field>general link</field>
    </skipDeepScanByFieldType>
    <onlyDeepScanByPaths hint="list">
       <content>/sitecore/content</content>
       <content>/sitecore/media library</content>
    </onlyDeepScanByPaths>
    <skipDeepScanTemplates hint="list" />
  </processor>
</getItemReferences>

Source code

The extended processor source code.