post: Optimising WordPress: Post Revisions and Autosave


Optimising Your WordPress Site: Post Revisions

Working With Wordpress



MySQL Optimisation WordPress

Post revisions is a feature in WordPress allowing you to keep track when editing content. Whenever a post or page is saved the old version is retained so it can be reverted back at any time. These revisions are by default never deleted so you always have a full history of all editorial changes.

It’s not immediately obvious how many revisions a post has. You’ll have to activate the revisions display option to show them. This is simply done through the ‘screen options’ drop-down in the top right of the edit screen in WordPress admin. Check the revisions option and the number of revisions will show in the Publish metabox.

You can see the potential problem however. For a large article with multiple updates this can lead to a lot of revisions. Each one of these is stored in the posts table with links to other tables. For a site with a large number of posts this can easily mount up to a significant number of entries often dwarfing actual post numbers. The increased table sizes have a knock on effect on with reduced MySQL efficiency.

There’s a couple of ways to reduce their impact, both reactive and proactive. It’s possible to cull the revisions count in the tables using SQL. Since most hosting comes with some kind of MySQL admin UI it’s best to use that. Most commonly this is PHPMyAdmin. For example deleting post revisions from last year and beyond.

DELETE a,b,cFROM wp_posts a  LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)  LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)  WHERE a.post_type = 'revision'AND a.post_date < '2015-01-01';

For the less technically-minded or adventurous there’s always a plugin around that will do the job. A quick search shows a list of potential candidates.

A proactive measure, either for new or cleaned-down sites, is to set a limit on the number of revisions WordPress is allowed to set. Once this limit is reached then it works by FIFO – first-in-first-out – to remove the earliest revision and replace it with the latest. What number to set is a personal preference. I like to set it to 3 – 5. This is done in the WP config file. Open wp-config and add the following:

define('WP_POST_REVISIONS', false); // Turns off revisions

define('WP_POST_REVISIONS', 3); // Limit of 3 revisions

Another aid is to set the time between post autosaves. The last autosave datetime is shown to the bottom right of the content editor. e.g. ‘Draft saved at 12:15:21 pm.’ or ‘ Last edited by admin on March 23, 2015 at 12:18 pm’. By default autosaves are kept after 60 seconds of inactivity, one autosave on a rolling basis. To change this in the config file:

define('AUTOSAVE_INTERVAL', 300 ); //Inverval in seconds

Hopefully this will help you keep your WP site lean. I’d also recommend optimising your WP tables monthly to keep the table indexes optimal.

comments powered by Disqus