mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Comments: Ignore the 'fields' parameter in the comment query cache.
`WP_Comment_Query` always queries runs an ID query, and so is unaffected by the 'fields' parameter. As such, 'fields' can be ignored when building a cache key for the results of the ID query. Props spacedmonkey. Fixes #41348. git-svn-id: https://develop.svn.wordpress.org/trunk@41190 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2877,4 +2877,78 @@ class Tests_Comment_Query extends WP_UnitTestCase {
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
$this->assertEqualSets( array( $c ), $q->comments );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41348
|
||||
*/
|
||||
public function test_count_query_should_miss_noncount_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
|
||||
$query_1 = $q->query( array(
|
||||
'fields' => 'ids',
|
||||
'number' => 3,
|
||||
'order' => 'ASC',
|
||||
) );
|
||||
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
|
||||
$query_2 = $q->query( array(
|
||||
'fields' => 'ids',
|
||||
'number' => 3,
|
||||
'order' => 'ASC',
|
||||
'count' => true,
|
||||
) );
|
||||
$this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41348
|
||||
*/
|
||||
public function test_count_query_should_hit_count_cache() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
|
||||
$query_1 = $q->query( array(
|
||||
'fields' => 'ids',
|
||||
'number' => 3,
|
||||
'order' => 'ASC',
|
||||
'count' => true,
|
||||
) );
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
|
||||
$query_2 = $q->query( array(
|
||||
'fields' => 'ids',
|
||||
'number' => 3,
|
||||
'order' => 'ASC',
|
||||
'count' => true,
|
||||
) );
|
||||
$this->assertEquals( $number_of_queries, $wpdb->num_queries );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41348
|
||||
*/
|
||||
public function test_different_values_of_fields_should_share_cached_values() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Comment_Query();
|
||||
|
||||
$query_1 = $q->query( array(
|
||||
'fields' => 'all',
|
||||
'number' => 3,
|
||||
'order' => 'ASC',
|
||||
) );
|
||||
$number_of_queries = $wpdb->num_queries;
|
||||
|
||||
$query_2 = $q->query( array(
|
||||
'fields' => 'ids',
|
||||
'number' => 3,
|
||||
'order' => 'ASC',
|
||||
) );
|
||||
|
||||
$this->assertEquals( $number_of_queries, $wpdb->num_queries );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user