Make WordPress Core


Ignore:
Timestamp:
08/30/2016 02:48:00 PM (10 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/query.php

    r38398 r38446  
    24962496
    24972497        /**
     2498         * @ticket 37696
     2499         */
     2500        public function test_hierarchy_should_be_filled_when_cache_is_incomplete() {
     2501                global $wpdb;
     2502
     2503                $p = self::factory()->post->create();
     2504                $comment_1 = self::factory()->comment->create( array(
     2505                        'comment_post_ID' => $p,
     2506                        'comment_approved' => '1',
     2507                ) );
     2508                $comment_2 = self::factory()->comment->create( array(
     2509                        'comment_post_ID' => $p,
     2510                        'comment_approved' => '1',
     2511                        'comment_parent' => $comment_1,
     2512                ) );
     2513                $comment_3 = self::factory()->comment->create( array(
     2514                        'comment_post_ID' => $p,
     2515                        'comment_approved' => '1',
     2516                        'comment_parent' => $comment_1,
     2517                ) );
     2518                $comment_4 = self::factory()->comment->create( array(
     2519                        'comment_post_ID' => $p,
     2520                        'comment_approved' => '1',
     2521                        'comment_parent' => $comment_2,
     2522                ) );
     2523
     2524                // Prime cache.
     2525                $q1 = new WP_Comment_Query( array(
     2526                        'post_id' => $p,
     2527                        'hierarchical' => true,
     2528                ) );
     2529                $q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' );
     2530                $this->assertEqualSets( array( $comment_1, $comment_2, $comment_3, $comment_4 ), $q1_ids );
     2531
     2532                // Delete one of the parent caches.
     2533                $last_changed = wp_cache_get( 'last_changed', 'comment' );
     2534                $key = md5( serialize( wp_array_slice_assoc( $q1->query_vars, array_keys( $q1->query_var_defaults ) ) ) );
     2535                $cache_key = "get_comment_child_ids:$comment_2:$key:$last_changed";
     2536                wp_cache_delete( $cache_key, 'comment' );
     2537
     2538                $q2 = new WP_Comment_Query( array(
     2539                        'post_id' => $p,
     2540                        'hierarchical' => true,
     2541                ) );
     2542                $q2_ids = wp_list_pluck( $q2->comments, 'comment_ID' );
     2543                $this->assertEqualSets( $q1_ids, $q2_ids );
     2544        }
     2545
     2546        /**
    24982547         * @ticket 27571
    24992548         */
Note: See TracChangeset for help on using the changeset viewer.