WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/07/2016 02:26:21 PM (4 years ago)
Author:
boonebgorges
Message:

Comments: Cache results of SELECT FOUND_ROWS() query.

When comment IDs are fetched from the cache rather than the database,
the subsequent SELECT FOUND_ROWS() query will not return the correct value.
To avoid unnecessary queries, we cache the results of the found_comments
query alongside the comment IDs.

Props spacedmonkey.
Fixes #37184.

File:
1 edited

Legend:

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

    r37954 r38001  
    21532153
    21542154    /**
     2155     * @ticket 37184
     2156     */
     2157    public function test_found_rows_should_be_fetched_from_the_cache() {
     2158        $comments = self::factory()->comment->create_many( 3, array( 'comment_post_ID' => self::$post_id ) );
     2159
     2160        // Prime cache.
     2161        new WP_Comment_Query( array(
     2162            'post_id' => self::$post_id,
     2163            'number' => 2,
     2164            'no_found_rows' => false,
     2165        ) );
     2166
     2167        $q = new WP_Comment_Query( array(
     2168            'post_id' => self::$post_id,
     2169            'number' => 2,
     2170            'no_found_rows' => false,
     2171        ) );
     2172
     2173        $this->assertEquals( 3, $q->found_comments );
     2174        $this->assertEquals( 2, $q->max_num_pages );
     2175    }
     2176
     2177    /**
    21552178     * @ticket 8071
    21562179     */
Note: See TracChangeset for help on using the changeset viewer.