Sitecore Publish Queue and Incremental Publish

I’ve recently been looking into the Publish Queue and using Incremental publish on our projects.
Out of the site publish modes available, Incremental publish is the quickest publishing option.

I wanted to look into how this works.
In the past we’ve always made our updates and individually published every changed item on it’s own. This can be very time consuming so I wanted to see if there’s a better way.

Ways to View the Publish Queue

Using the Sitecore API

I found some different ways to view the publish queue.

Beginning with Brian Pedersen’s blog post I wrote an application that simply lists the publish queue using his ‘current view’ method.

Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master");
Sitecore.Data.Database web = Sitecore.Data.Database.GetDatabase("web");
 
Sitecore.Publishing.PublishOptions options = new Sitecore.Publishing.PublishOptions(master, web, Sitecore.Publishing.PublishMode.Incremental, Sitecore.Globalization.Language.Parse("en"), DateTime.Now);
 
// Get all the publishing candidates
System.Collections.Generic.IEnumerable candidates = Sitecore.Publishing.Pipelines.Publish.PublishQueue.GetPublishQueue(options);

Using Sitecore Rocks

In Rocks you can access the publish queue through the context menu by right clicking on an item in Sitecore Explorer and choosing
Tools -> Publishing -> Publish Queue
Publish Queue - Sitecore Rocks
Publish Queue - Sitecore Rocks

Note: You can also access this quickly using Commandy or by adding the selection to your favourites if you use it often enough.

Looking at the SQL table dbo.PublishQueue

If you open up SQL Server and locate the Publish Queue table in your master database you can view all the entries that Sitecore has made to it.
Publish Queue - SQL Table

Comparing all the queues

When looking at these three options I found that I was getting slightly different subsets in each.
The largest set of results came from the SQL Server table, while the smallest set came from the API code.

I noticed the following:-

  • The SQL table could contain multiple references to the same item. I assume this means that the one item could have been edited multiple times, and been added to the table each time.
  • The Rocks Publishing Queue viewer contained singular references to all items found in the SQL table.
  • The API code gave a subset of the Rocks queue, and only listed items that had been updated relatively recently.

How does incremental publish work with the Publish Queue

The incremental publish works the same way as the API code above. I found that the API code only grabs items that were updated more recently than the date and time of the last incremental publish.
Sitecore stores the date and time of the last publish in the dbo.Properties table for every target database and language.
This can also be accessed in code using:-

Database.Properties.GetLastPublishDate(Database target, Language language)

Code Reference

This is also how the Incremental Publish works. Sitecore grabs all the items from the Publish Queue table that were modified more recently than the last publish date.

By doing this, only recently changed items (in the final workflow state) will be published.