More bonkers comment cache cleanup: toggle wp_defer_comment_counting()
in wp_insert_post()
and wp_insert_attachment()
. Move the cache deletion in wp_update_comment_count_now()
to before the get_post()
call, so that the caches get deleted even if the post has already been deleted and the function returns early.
See #33875. git-svn-id: https://develop.svn.wordpress.org/trunk@34158 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
8cb6843170
commit
95795c1301
@ -1907,6 +1907,10 @@ function wp_update_comment_count_now($post_id) {
|
||||
$post_id = (int) $post_id;
|
||||
if ( !$post_id )
|
||||
return false;
|
||||
|
||||
wp_cache_delete( 'comments-0', 'counts' );
|
||||
wp_cache_delete( "comments-{$post_id}", 'counts' );
|
||||
|
||||
if ( !$post = get_post($post_id) )
|
||||
return false;
|
||||
|
||||
@ -1916,9 +1920,6 @@ function wp_update_comment_count_now($post_id) {
|
||||
|
||||
clean_post_cache( $post );
|
||||
|
||||
wp_cache_delete( 'comments-0', 'counts' );
|
||||
wp_cache_delete( "comments-{$post_id}", 'counts' );
|
||||
|
||||
/**
|
||||
* Fires immediately after a post's comment count is updated in the database.
|
||||
*
|
||||
|
@ -1394,7 +1394,7 @@ function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
|
||||
}
|
||||
$labels = array_merge( $defaults, $object->labels );
|
||||
$object->labels = (object) $object->labels;
|
||||
|
||||
|
||||
return (object) $labels;
|
||||
}
|
||||
|
||||
@ -2370,9 +2370,14 @@ function wp_delete_post( $postid = 0, $force_delete = false ) {
|
||||
// Point all attachments to this post up one level.
|
||||
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
|
||||
|
||||
wp_defer_comment_counting( true );
|
||||
|
||||
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
|
||||
foreach ( $comment_ids as $comment_id )
|
||||
foreach ( $comment_ids as $comment_id ) {
|
||||
wp_delete_comment( $comment_id, true );
|
||||
}
|
||||
|
||||
wp_defer_comment_counting( false );
|
||||
|
||||
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
|
||||
foreach ( $post_meta_ids as $mid )
|
||||
@ -4637,9 +4642,14 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
|
||||
// Delete all for any posts.
|
||||
delete_metadata( 'post', null, '_thumbnail_id', $post_id, true );
|
||||
|
||||
wp_defer_comment_counting( true );
|
||||
|
||||
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
|
||||
foreach ( $comment_ids as $comment_id )
|
||||
foreach ( $comment_ids as $comment_id ) {
|
||||
wp_delete_comment( $comment_id, true );
|
||||
}
|
||||
|
||||
wp_defer_comment_counting( false );
|
||||
|
||||
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
|
||||
foreach ( $post_meta_ids as $mid )
|
||||
|
Loading…
Reference in New Issue
Block a user