Sitecore Incremental Publish Summary

When performing publishing on sitecore, there is no statistics that enables the user to know how many items are going to be processed. In this post, I will be explaining how to get the number of items that needs to be processed when using Incremental Publish.

First, before we start, I would like to explain the reasons why I have not opted to check the number of items to be processed by the Full and Smart Publish.

Why Not Choosing Smart Publish?

Smart publish will make use of a root item. If you are using the Publish Item Option, then the root will be the selected item and when you are using the Publish Site Option, the Root Item will be the Sitecore Node Item. Due to this, if the item has large number of descendants, the amount of time and resource in order to calculate the total items is too excessive. Moreover, Smart Publish will compare versions which is another load. These aspects will affect the performance of the instance.

Why Not Choosing Full Publish?

Same as the Smart Publish, full publish will also make use of a root item and will republish all the items in the CMS to the target database. Again, this will put extra load on the performance of the instance since retrieving the total number of items is too time consuming, thus slowing down the publishing.

Why Choosing Incremental Publish?

Incremental Publish will only publish items that have been created, modified or deleted. It also make use of the publish queue table and the timestamp of the last published from the Properties table.

I have already implemented a tool which will provide the following information when performing an Incremental Publish:

  1. Max number of Items to be Processed.
  2. Owner of the publish.
  3. Number of items already processed.
  4. Number of items that have been modified, skipped, updated, created and deleted.
  5. List of item paths that have been published.

The tool can be downloaded from the Sitecore Marketplace at the following link: Publish Summary

Publish Summary

By making use of the event publish:itemProcessed, I have retrieved the number of items that will be processed along with the items that have been processed. The event publish:itemProcessed, as its name says, provides information about the item that has just been published.

Calculation

In order to get the maximum number of items to be processed, the following calculation had to be performed:

Key:

NL = Number of languages selected to publish the item

IP = Item to Process

Calculation:

Total = (NL)² + NL x IP

From this calculation, I have written the following code to get the processed item:


public void OnItemProcessed(object sender, EventArgs args)
{
    var itemArgs = args as ItemProcessedEventArgs;

    if (itemArgs != null)
    {
        var publishContext = itemArgs.Context.PublishContext;

        if (itemArgs.Context.PublishOptions.Mode == PublishMode.Incremental)
        {
            var processedItems = publishContext.ProcessedItems;

            var itemsToProcess = PublishQueue.GetPublishQueue(itemArgs.Context.PublishOptions).Count();

            var totalItems = Math.Pow(itemArgs.Context.PublishContext.Languages.Count(), 2) +
                             (itemArgs.Context.PublishContext.Languages.Count() * itemsToProcess);

            foreach (var processedItem in processedItems)
            {
                var item = Factory.GetDatabase("master").Items.GetItem(new ID(processedItem));

                if (item != null)
                {
                    var publishedItems = new PublishedItemEntity
                    {
                        ItemId = item.ID,
                        ItemName = item.DisplayName,
                        ItemPath = item.Paths.ContentPath
                    };
                }                
            }
        }
    }
}

From this code and using the Sitecore Event Raiser, I pass the updated values to my Sitecore UI.

This is how I have achieved to retrieve the maximum number of items to be processed when performing an Incremental Publish.

Note: If you are using the tool, here is a brief How To:

  1. Launch your incremental publish.
  2. Launch the Sitecore module. Path: Sitecore -> Publish Summary
Advertisements

One thought on “Sitecore Incremental Publish Summary

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s