From cae71f232cb466327f1e993a21b20b9ce7cb86a2 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Thu, 4 Nov 2021 23:56:58 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@52015 git-svn-id: http://core.svn.wordpress.org/trunk@51606 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 4 ++-- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 0f75bf537e..b6ca7c24d3 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3236,7 +3236,7 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { wp_defer_comment_counting( true ); - $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ) ); + $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $postid ) ); foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); } @@ -6194,7 +6194,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { 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 ) ); + $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 ) ); foreach ( $comment_ids as $comment_id ) { wp_delete_comment( $comment_id, true ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 2c8c21e10d..acb681e1d8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52014'; +$wp_version = '5.9-alpha-52015'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.