Opened 13 years ago
Closed 12 years ago
#19663 closed enhancement (fixed)
auto-draft garbage collection should be done via cron, not when starting new post
Reported by: | _ck_ | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | 3.3 |
Component: | Performance | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
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.
Attachments (2)
Change History (12)
#1
@
13 years ago
- Milestone changed from Awaiting Review to 3.4
- Type changed from defect (bug) to enhancement
#2
@
13 years ago
- Cc mgolawala added
- Keywords has-patch added
- Version changed from 3.3 to 3.3.1
I moved the inline deletion of auto-posts from the wp-admin/includes/post.php: get_default_post_to_edit and made it part of the daily garbage collection cron entry that cleans out posts, comments, pages, attachments etc.
Let me know if you would like it to be organized differently. From a code organization standpoint, I could use one of the alternate twotechniques:
- Create a separate cron schedule for it to be more frequent than daily (configured via UI?)
- Have the post.php entry queue up the separate cron entry for auto-post garbage collection, and then have the auto-post garbage collection function deque it self. This would end up invoking the garbage collection as often as before, just asynchronously.
Let me know your thoughts.
#3
@
13 years ago
- Version changed from 3.3.1 to 3.3
The version field is used to indicate the first version in which a problem was identified in, or reproduced in.
#7
@
12 years ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In [20440]:
Yeah, this is a good idea.