Make WordPress Core

Changeset 52015


Ignore:
Timestamp:
11/04/2021 11:55:21 PM (3 years ago)
Author:
peterwilsoncc
Message:

Comments: Avoid reparenting during post deletion.

Delete comments in a descending order by comment ID when deleting a post.

This avoids the expense of additional database queries required to re-parent threaded comments that are themselves about to be deleted.

Props Mte90, andraganescu, johnbillion, hellofromTonya, peterwilsoncc.
Fixes #37703.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r51965 r52015  
    32373237    wp_defer_comment_counting( true );
    32383238
    3239     $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) );
     3239    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) );
    32403240    foreach ( $comment_ids as $comment_id ) {
    32413241        wp_delete_comment( $comment_id, true );
     
    61956195    wp_defer_comment_counting( true );
    61966196
    6197     $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) );
     6197    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $post_id ) );
    61986198    foreach ( $comment_ids as $comment_id ) {
    61996199        wp_delete_comment( $comment_id, true );
Note: See TracChangeset for help on using the changeset viewer.