[wp-trac] [WordPress Trac] #19663: auto-draft garbage collection should be done via cron, not when starting new post
WordPress Trac
wp-trac at lists.automattic.com
Sat Dec 24 13:58:56 UTC 2011
#19663: auto-draft garbage collection should be done via cron, not when starting
new post
--------------------------+-----------------------------
Reporter: _ck_ | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Performance | Version: 3.3
Severity: normal | Keywords:
--------------------------+-----------------------------
On small sites this isn't a problem but active, larger sites with multiple
authors, the issue becomes magnified.
A user should not have to wait when clicking on post -> add new
but it can happen because of auto-draft deletion is forced to happen at
that time for ALL authors in a system.
in `wp-admin/includes/post.php` `function get_default_post_to_edit`
garbage collection is currently done like so
{{{
if ( $create_in_db ) {
// Cleanup old auto-drafts more than 7 days old
$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts
WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) >
post_date" );
foreach ( (array) $old_posts as $delete )
wp_delete_post( $delete, true ); // Force delete
$post_id = wp_insert_post( array( 'post_title' => __(
'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' )
);
$post = get_post( $post_id );
if ( current_theme_supports( 'post-formats' ) &&
post_type_supports( $post->post_type, 'post-formats' ) && get_option(
'default_post_format' ) )
set_post_format( $post, get_option(
'default_post_format' ) );
}
}}}
Seems trivial but it's not. It can cause a large number of queries to
occur as meta is also cleared and causes plugins related to new/deleted
posts to fire. Even if there is nothing to cleanup, the code still fires
for every author on every new post.
I propose a simple change instead, where the deletion code is moved simply
to it's own small function and added to a once-a-day wp-cron that could be
fired for example early in the morning or re-scheduled as desired.
This way an author can be guaranteed to have faster access to "add new"
since it's otherwise a very complex page that needs many more of it's own
queries to initialize and often several plugins to affect the new post
abilities.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/19663>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list