Sitecore Link Database Basics

Challenge:

We are facing one challenge with link database, The behavior is as following:

  1. At times our content authors reported that, few renderings stopped working. After doing investigation we found that they have deleted Items — which they have assigned to a page in fields. But when they recycled/delete item — they didn’t get any broken link pop up and they confidently deleted items.  But due to such behavior, they can’t say confidently whether there is any broken link [Whether current page is linked somewhere or not] and that decreased reliability of recycle/delete functionality.
  2. It decreases reliability of recycle/delete functionality, and takes the lot of human hours to find out, whether this page got any references or not
  3. No, at this point of time, we don’t have steps to reproduce this issue. We faced this issue for one section [bunch of items] on our CM Environment. To reproduce this scenario, what we did is created package from CM Environment and installed it in our local environment. And here it was working fine. Means links were perfect! [As far as I can think of a reason behind this is — When we install package — SC must be rebuilding link database]

You are also facing similar challenge?

We raised this issue with Sitecore support guys, And as always they have been helpful for us to dig more in this issue. We’ve not been able to find the solution yet. But during discussion we understood Links Database Basics and found few behaviors, Which has not been documented anywhere. And I believe It will be a good to know for you as well!

In summary, This post will cover following topics:

  1. Basics of Sitecore Links Database — How it works?
  2. Few tips and tricks related to links database.

So, here we go!

Solution:

This is what we checked during this whole ticket:

  1. Checked CustomFields configuration :When Sitecore updates links for the item, it’s expecting that field type is derived from Sitecore.Data.Fields.CustomField.
    Sitecore searches field type by name in the /App_Config/FieldTypes.config and try to cast this type to CustomField and use some methods from this class (links update logic). I would suggest the following solution for your issue:
    1. Add the following field type to FieldTypes.config:
    <fieldType name=”SiteSubtree” type=”Sitecore.Data.Fields.MultilistField,Sitecore.Kernel” />
    2. Rebuild Links database (it’s important!)
    This approach is working properly on my side. Please not that all your overriden SiteSubtree methods will be used in this  case, not the MultilistField ones.

    We verified it, And it was already as per standards in our case.

  2. Do Rebuild link database — Unfortunately this is also not an option for us, because our DB size is huge and rebuild link DB will take the lot of time, which will need an outage.
  3. So, If you can’t rebuild entire link database now, You can suggest you to use the following code to rebuild only necessary items which can be affected by this problem (where mentioned fields is used): Globals.LinkDatabase.UpdateReferences(item)
  4. We checked all above options. And nothing was fitting in our need. So, as per basics concept, We stepped back and asked SC Support guys “How Links Database works?“, and they explained it very nicely:
    1. Generally, links in Link Database are updated using Sitecore.Links.ItemEventHandler class. There are 3 events that are
      handled by Sitecore.Links.ItemEventHandler: item:deleted (OnItemDeleted method), item:saved (OnItemSaved method), item:versionRemoved (OnVersionRemoved method)
    2. When you delete an item, Broken Links validation is running before the item is deleted, it allows you to decide what you
      will do with broken links. This validation is run as a processor in the <uiDeleteItems> pipeline, please see the processor
      definition in your web.config: <processor mode=”on” type=”Sitecore.Shell.Framework.Pipelines.DeleteItems,Sitecore.Kernel” method=”CheckLinks” />
  5. Following are the few scenarios In which case such issue can occur:
    1. Using of the custom code that stop the link database from updating: Sitecore.Links.LinkDisabler(){….}
    2. Synchronizing of Link Database on your scaling environment has not been configured properly. You can read about this in the following article: http://sdn.sitecore.net/upload/sitecore6/64/scaling_guide_sc63-64-a4.pdf (Chapter 3.6.1)
    3. Following custom code can disable invoking of events : using (new Sitecore.Data.Events.EventDisabler()){…..}
    4. item.Editing.EndEdit(true, true) method. A new link won’t be added to the LinkDatabase if the corresponding multilist field (for example) will be updated in the ‘silent’ mode. And therefore the ‘Broken link’ dialog won’t work for this link.

We are still working on to find the root cause of this issue (Because of our Multisite environment) . But now, We know where to look at? And we know exactly what all are the possible options for such behavior. And I’m sure you will also find this information useful while troubleshooting such challenge.

I’m sure one day, We will find root cause and will share it with you for sure! And we expect same from you! 🙂

Happy Linking! 🙂

PS : Special thanks to  Alexey Zhukov and Yuriy Yurkovsky(Sitecore Support) for providing this suggestion and Devashri who did all this investigation and worked on this challenge!

John west’s all articles listing page link

Before couple of days, I started following John West (If you are in Sitecore world and don’t know about John West then it is a surprise for me! Anyways, just a short description about him — John West is a CTO of Sitecore, and he writes regular articles which are very helpful and insightful for every Sitecorian, He is also active on SDN forums — You post a question and he will reply ASAP! and above all he is a wonderful human being — who loves to help others! — I can say this as I was lucky enough to meet him in person) on Twitter and in response to that John welcomed me with his all article’s listing page link. Which I found very useful and thought to share with you as well!

http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Archive.aspx

If you like it say thanks to John West!

Happy Sitecoring! 🙂