Disablers, disablers, disablers, disablers: A lesson in mass Sitecore updates.

In my previous post I talked about an issue we were having with a large number of items (200,000+ items) existing in Sitecore.  Well, after the initial import, we needed to make some changes to those items.  We found that the code we had written was taking an extremely long time.  I took a look at the code that was written and was reminded of a project where we had to do something similar.  This particular project had an import process that was only importing about 10,000 items, but it was taking almost 36 hours to complete.  I put my colleague John Kurtis on a mission to speed it up.

About a day later, John informed me that he got the import process down to only 20 minutes!  A dramatic improvement indeed!

Here’s how he did it:

using (new SecurityDisabler())
using (new ProxyDisabler())
using (new DatabaseCacheDisabler())
using (new EventDisabler())
using (new BulkUpdateContext())
{
try
{
Sitecore.Configuration.Settings.Indexing.Enabled = false;

for (int i = start; i <= end; i++)
{
// update / insert / add / delete items here
}
}
finally
{
Sitecore.Configuration.Settings.Indexing.Enabled = true;
}
}

Essentially, add the 4 disablers, the bulk update context and the disabling of indexing.  You will need to clear the Sitecore cache’s and then rebuild any indexes that refer to the items that you were updating.

As an aside, notice the shorthand for the using blocks. You can stack them without needed additional closing brackets.

One thought on “Disablers, disablers, disablers, disablers: A lesson in mass Sitecore updates.

Add yours

Leave a Reply

Powered by WordPress.com.

Up ↑

%d bloggers like this: