What is the Difference Between Smart Publish and Republish?
January 17, 2017
As a developer at GeekHive, who’s spent years working in Sitecore, gaining experience with what feels like every facet of the application, I’m surprised to find there are still a few features I have questions about. In this post, I’ll explore the difference between Smart Publish and Republish since publishing is a feature I use on a daily basis.
Whether it be the publishing dialog, writing custom publishing processors or programmatically publishing items, it comes up all the time. When performing a publish operation at any level (IDE vs. in code) the Publishing Mode must be chosen. There are several modes to choose from: Full, Incremental, Single Item, and Smart. When speaking specifically about the options available in Content Editor, a publisher may choose either Republish or Smart.
The Difference Between Smart Publish and Republish
These two options come with the following explanatory text:
- Smart: publish differences between source and target database
- Republish: publish everything
Given these brief explanations, a lot of assumptions are made. Since assumptions often lead to development issues, I wanted to understand exactly what the difference was between the two so that if one didn’t work properly, I would have an understanding of what was executing in the code in order to intelligently address the problem. To try to get to the bottom of it, I reached out and asked a few other seasoned Sitecore pros what they thought and received varying responses each time -from mentions of the Sitecore Links database to comparing entries in the Sitecore History table. Turns out there’s a lot of confusion on this very topic so I took it upon myself to dig deeper.
Smart Publish Is Smart
After dissecting the entire Publish journey via decompilation, I discovered that fundamentally speaking, Smart Publish and republish Only differ by a single parameter – compareRevisions. This is a property of the PublishOptions class and is set within Sitecore.Publishing.PublishManager.PublishSmart. With this single flag set to true, the Smart Publish is identical in every other way to Republish until the code is traced to Sitecore.Publishing.PublishHelper.PublishVersionToTarget.
From this method, we learn the following…
Smart Publish will skip (aka not update) an individual item if ALL of the following conditions are true:
The conditional is an AND conditional, so if any of these steps fail, the next sequential condition is not evaluated.
- The revision number between source and target are identical.
- The revision number is the GUID stored in the _revision field.
- Keep in mind that the revision number differs from the version number – which is an integer and not stored as a field on the item.
- The revision number is modified on every save of an item. The Item Manager class automatically changes the revision number. Regardless of the method used to update an item, all paths lead through the Item Manager class and therefore is impossible to avoid.
- All unversioned field values on an item are identical.
- Unversioned fields are not tied to a version, so comparing these fields in particular catches a change to an item that was not caught by a possible revision number difference.
- The source and target items contain the same number of fields.
Note: There are a few additional checks if an item is a clone that are not covered by this blog post.
Before writing this post, I was convinced there was a gap in the logic of Smart Publish, but after my extensive review I’m now convinced the opposite is true. For standard Sitecore work, Smart Publish is quicker and performs as its name implies- Smart-ly. The only scenario I can come up with where Smart Publish is not ideal is if an index becomes corrupt and requires updating and is relying on an OnPublishEnd update strategy. In that case, Republish will trigger all items to be re-indexed.
Conclusion: Smart Publish Takeaways
As a final summary, the following statements are all true:
- Smart Publish will publish new items to the target database.
- Smart Publish will delete items from the target database that were removed in the source database.
- Modifying an item in any way will leave an indicator that will cause Smart Publish to overwrite the target item version with the source item version.
- Changing a versioned field will change the revision field.
- Changing an unversioned field will be seen during the Smart Publish comparison of the source and target item.
I, myself, often defaulted to Republish since I never fully comprehended the scope of Smart Publish. Hopefully, this post clears up some confusion around Smart Publish.
Stay up to date with our email updates!