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
Looking at the SQL table dbo.PublishQueue
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)
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.