Umbraco Preview Performance (v.4.5.2)

Recently had an issue with the Umbraco preview feature, where editors can view saved (but not published) changes in the actual site.
This adds a nice little “Preview Mode” banner top-right, but otherwise let’s you browse around the site as you please.
The way this feature works, is it copies the XML file cache (\app_data\umbraco.config) and then updates this copy with any “saved but not yet published” content nodes present in the site.
On a large site however (35MB content file) – this runs painfully slow, and with multiple editors the performance issue can affect your server(s) to the point where the normal site is no longer functional.
Looking into the issue in the Umbraco source we found that the core “GetXML” method on the UmbracoContext class, has a little “IsPreview” switch (this flag is set as a cookie called PreviewSet btw) – and the issue is that the “GetPreviewXML” function is uncached, and so will read the full XML file from disk on every single call to “GetXML”… and this has a lot of calls. Things like XSLT macros will repeatedly request the XML content, so on a complicated page you can see hundreds of calls to GetXML – meaning in our case that each page load (with the user in PreviewMode) would literally ask the server to load a 35MB text file into memory about 200 times.
The below solved the problem – but code could be tidied a lot (to mirror the core XML caching functionality).

//TP 20110317 - add a little caching to this:
private PreviewContent _previewContent;
public XmlDocument GetXml()
    if (InPreviewMode)
		if (_previewContent == null)
			_previewContent = new PreviewContent(new Guid(StateHelper.GetCookieValue("PreviewSet")));
		return _previewContent.XmlContent;
        return content.Instance.XmlContent;

The above will read the preview XML from disk once per page request, and then serve that from the local variable for all subsequent calls to GetXML during that page request.


3 Responses to Umbraco Preview Performance (v.4.5.2)

  1. Pingback: Umbraco Examine – Indexing Large Sites – ThreadAbort Timeout Error Workaround « Blog Bustin' .NET Beats

  2. Sounds great, has this been added to the core of Umbraco?
    If not, where can I get the code?

    • blogbustingbeats says:

      Hey – I don’t know if it was integrated, but we did make them aware of the problem so I would have thought they have resolved it somehow (probably in a more elegant way than the above) – you could download the source of whatever Umbraco version you are using and search for InPreviewMode and see how it’s being used…

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your 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

%d bloggers like this: