mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-03-31 02:34:38 +00:00
Comments: Don't do direct SQL query when fetching decendants.
The SQL query was built using the clauses compiled when querying for top-level comments. But in cases where the top-level comment query results are already in the cache, the SQL clauses are not built, and so are unavailable for `fill_descendants()`. Instead, we call `get_comments()`, using modified versions of the parameters passed to the main `WP_Comment_Query` class. Props Akeif, Rarst for testing. Fixes #37696. git-svn-id: https://develop.svn.wordpress.org/trunk@38446 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2494,6 +2494,55 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37696
|
||||
*/
|
||||
public function test_hierarchy_should_be_filled_when_cache_is_incomplete() {
|
||||
global $wpdb;
|
||||
|
||||
$p = self::factory()->post->create();
|
||||
$comment_1 = self::factory()->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_approved' => '1',
|
||||
) );
|
||||
$comment_2 = self::factory()->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_approved' => '1',
|
||||
'comment_parent' => $comment_1,
|
||||
) );
|
||||
$comment_3 = self::factory()->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_approved' => '1',
|
||||
'comment_parent' => $comment_1,
|
||||
) );
|
||||
$comment_4 = self::factory()->comment->create( array(
|
||||
'comment_post_ID' => $p,
|
||||
'comment_approved' => '1',
|
||||
'comment_parent' => $comment_2,
|
||||
) );
|
||||
|
||||
// Prime cache.
|
||||
$q1 = new WP_Comment_Query( array(
|
||||
'post_id' => $p,
|
||||
'hierarchical' => true,
|
||||
) );
|
||||
$q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' );
|
||||
$this->assertEqualSets( array( $comment_1, $comment_2, $comment_3, $comment_4 ), $q1_ids );
|
||||
|
||||
// Delete one of the parent caches.
|
||||
$last_changed = wp_cache_get( 'last_changed', 'comment' );
|
||||
$key = md5( serialize( wp_array_slice_assoc( $q1->query_vars, array_keys( $q1->query_var_defaults ) ) ) );
|
||||
$cache_key = "get_comment_child_ids:$comment_2:$key:$last_changed";
|
||||
wp_cache_delete( $cache_key, 'comment' );
|
||||
|
||||
$q2 = new WP_Comment_Query( array(
|
||||
'post_id' => $p,
|
||||
'hierarchical' => true,
|
||||
) );
|
||||
$q2_ids = wp_list_pluck( $q2->comments, 'comment_ID' );
|
||||
$this->assertEqualSets( $q1_ids, $q2_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 27571
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user