Make WordPress Core

Ticket #37696: 37696.diff

File 37696.diff, 3.1 KB (added by boonebgorges, 8 years ago)
  • src/wp-includes/class-wp-comment-query.php

    diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php
    index 0920ca2..825e9d8 100644
    class WP_Comment_Query { 
    995995                        }
    996996
    997997                        if ( $uncached_parent_ids ) {
    998                                 $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $uncached_parent_ids ) ) . ')';
    999                                 $level_comments = $wpdb->get_results( "SELECT $wpdb->comments.comment_ID, $wpdb->comments.comment_parent {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" );
     998                                // Fetch this level of comments.
     999                                $parent_query_args = $this->query_vars;
     1000                                foreach ( $exclude_keys as $exclude_key ) {
     1001                                        $parent_query_args[ $exclude_key ] = '';
     1002                                }
     1003                                $parent_query_args['parent__in']    = $uncached_parent_ids;
     1004                                $parent_query_args['no_found_rows'] = true;
     1005                                $parent_query_args['hierarchical']  = false;
     1006
     1007                                $level_comments = get_comments( $parent_query_args );
    10001008
    10011009                                // Cache parent-child relationships.
    10021010                                $parent_map = array_fill_keys( $uncached_parent_ids, array() );
  • tests/phpunit/tests/comment/query.php

    diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php
    index 219e2d1..1c4544b 100644
    class Tests_Comment_Query extends WP_UnitTestCase { 
    24992499        }
    25002500
    25012501        /**
     2502         * @ticket 37696
     2503         */
     2504        public function test_hierarchy_should_be_filled_when_cache_is_incomplete() {
     2505                global $wpdb;
     2506
     2507                $p = self::factory()->post->create();
     2508                $comment_1 = self::factory()->comment->create( array(
     2509                        'comment_post_ID' => $p,
     2510                        'comment_approved' => '1',
     2511                ) );
     2512                $comment_2 = self::factory()->comment->create( array(
     2513                        'comment_post_ID' => $p,
     2514                        'comment_approved' => '1',
     2515                        'comment_parent' => $comment_1,
     2516                ) );
     2517                $comment_3 = self::factory()->comment->create( array(
     2518                        'comment_post_ID' => $p,
     2519                        'comment_approved' => '1',
     2520                        'comment_parent' => $comment_1,
     2521                ) );
     2522                $comment_4 = self::factory()->comment->create( array(
     2523                        'comment_post_ID' => $p,
     2524                        'comment_approved' => '1',
     2525                        'comment_parent' => $comment_2,
     2526                ) );
     2527
     2528                // Prime cache.
     2529                $q1 = new WP_Comment_Query( array(
     2530                        'post_id' => $p,
     2531                        'hierarchical' => true,
     2532                ) );
     2533                $q1_ids = wp_list_pluck( $q1->comments, 'comment_ID' );
     2534                $this->assertEqualSets( array( $comment_1, $comment_2, $comment_3, $comment_4 ), $q1_ids );
     2535
     2536                // Delete one of the parent caches.
     2537                $last_changed = wp_cache_get( 'last_changed', 'comment' );
     2538                $key = md5( serialize( wp_array_slice_assoc( $q1->query_vars, array_keys( $q1->query_var_defaults ) ) ) );
     2539                $cache_key = "get_comment_child_ids:$comment_2:$key:$last_changed";
     2540                wp_cache_delete( $cache_key, 'comment' );
     2541
     2542                $q2 = new WP_Comment_Query( array(
     2543                        'post_id' => $p,
     2544                        'hierarchical' => true,
     2545                ) );
     2546                $q2_ids = wp_list_pluck( $q2->comments, 'comment_ID' );
     2547                $this->assertEqualSets( $q1_ids, $q2_ids );
     2548        }
     2549
     2550        /**
    25022551         * @ticket 27571
    25032552         */
    25042553        public function test_update_comment_post_cache_should_be_disabled_by_default() {