Categories
Commerce Catalog Episerver Episerver Find

Disable Episerver Find on large Commerce Catalog updates

We are working in an Episerver implementation that has a huge Catalog. We have around 130.000 products, and each of those, has at least 1 variant below. Which give us around 260.000 entities.

One of the challenges that we have faced, was pushing updates from the PIM platform into Episerver. With that amount of items in the PIM, we have a lot of updates coming everyday, and performance is something to keep an eye on.
We were facing issues when the push from the PIM was taking place. After some investigation we realized that Find was pushing updates for each update that we were pushing from the PIM to Episerver. And both things happening at the same time was too much overhead.

In order to improve the performance of the Catalog import, we decided to take the following approach:

  1. Whenever we trigger the import of products from the PIM to Episerver, we disable the updates to Episerver Find.
  2. We run the import until it finished.
  3. We enable the updates from Episerver to Find.
  4. We trigger the job to re-index Episerver Find (Episerver Find Content Indexing Job)

The approach is really easy from the implementation point of view, so let’s see how it looks:

using EPiServer.Find.Cms;
//Basically this is what we need to disable
EventedIndexingSettings.Instance.EventedIndexingEnabled = false;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = false;
view raw DisableFind.cs hosted with ❤ by GitHub

And now let’s see it working in the implementation.

using EPiServer.Find.Cms;
using EPiServer.ServiceLocation;
using Mediachase.Commerce.Catalog.ImportExport;
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
public class CatalogImportManager : ICatalogImportManager
{
private readonly ILogManager _logManager;
private StringBuilder _stringBuilderResponse;
public CatalogImportManager(ILogManager logManager)
{
this._logManager = logManager;
this._stringBuilderResponse = new StringBuilder();
}
public string CatalogImport(Stream catalogMemoryStream)
{
// This is how we disable the updates to Find
EventedIndexingSettings.Instance.EventedIndexingEnabled = false;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = false;
try
{
XDocument catalogXml = XDocument.Load(catalogMemoryStream);
CatalogImportExport catalogImportExport = new CatalogImportExport();
catalogImportExport.ImportExportProgressMessage += CatalogImportExport_ImportExportProgressMessage;
catalogImportExport.Import(catalogXml, true);
catalogXml.Dispose();
}
catch (Exception ex)
{
this._logManager.WriteError("Error in ImportWithHandlers", ex);
//In case of any error, we need to remember to enable Find
EventedIndexingSettings.Instance.EventedIndexingEnabled = true;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = true;
throw;
}
//If everything worked fine, we enable Find
EventedIndexingSettings.Instance.EventedIndexingEnabled = true;
EventedIndexingSettings.Instance.ScheduledPageQueueEnabled = true;
return this._stringBuilderResponse.ToString();
}
private void CatalogImportExport_ImportExportProgressMessage(object source, ImportExportEventArgs args)
{
this._logManager.WriteError(args.Message);
this._stringBuilderResponse.Append(args.Message);
}
}

I am not elaborating how to trigger the Episerver Find Content Indexing Job, and you will find plenty of examples about how to do that. In our case, the solution was to schedule it at some specific time, when we knew that the import from the PIM server is already finished.

You can also find a similar, but more elaborated, approach in which Jeroen is keeping track of all the elements and providing methods to perform specific actions on them. Here is the link.

Please keep in mind that the code is only for educational purposes 🙂

In another post I will explain an easy way to include Pre-Import handlers and Post-Import handlers for the cases in which we need to do some small tweaks, updates and sanitize the XML file that goes into Episerver.

Hope this was useful!
Happy codding!

By Mauro Vieira Gonçalves

Episerver Lead at Valtech

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s