mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Multisite: Improve caching in WP_Network_Query by ignoring the $fields argument.
Prior to this change there were two different cache keys used for the same query. That is because regardless of the `$fields` argument, the query response will be the same. This was already fixed for `WP_Site_Query` in [41059]. Props spacedmonkey. Fixes #41347. git-svn-id: https://develop.svn.wordpress.org/trunk@41063 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -379,6 +379,79 @@ class Tests_Multisite_Network_Query extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEquals( $expected, $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41347
|
||||
*/
|
||||
public function test_wp_network_query_cache_with_different_fields_no_count() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Network_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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 41347
|
||||
*/
|
||||
public function test_wp_network_query_cache_with_different_fields_active_count() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Network_Query();
|
||||
|
||||
$query_1 = $q->query( array(
|
||||
'fields' => 'all',
|
||||
'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 41347
|
||||
*/
|
||||
public function test_wp_network_query_cache_with_same_fields_different_count() {
|
||||
global $wpdb;
|
||||
|
||||
$q = new WP_Network_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 );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user