Umbraco Database Size – Cleaning Unnecessary Versions

Lots of details on this here:
Including a good overview of the core Umbraco Database as well.


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.

Installing 3rd Party Libraries with NuGet

This is a very useful little tool: