mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Multisite: improve sites_pre_query and networks_pre_query filters, avoiding db queries.
Improve the `pre_query` filters in multisite classes introduced in r44983. Return (non null) values immediately, avoiding the database queries entirely, similar to other `pre_query` filters. Props spacedmonkey, SergeyBiryukov, felipeelia. Fixes #47599. git-svn-id: https://develop.svn.wordpress.org/trunk@46100 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -525,6 +525,7 @@ if ( is_multisite() ) :
|
||||
|
||||
/**
|
||||
* @ticket 45749
|
||||
* @ticket 47599
|
||||
*/
|
||||
public function test_networks_pre_query_filter_should_bypass_database_query() {
|
||||
global $wpdb;
|
||||
@@ -534,11 +535,7 @@ if ( is_multisite() ) :
|
||||
$num_queries = $wpdb->num_queries;
|
||||
|
||||
$q = new WP_Network_Query();
|
||||
$results = $q->query(
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
$results = $q->query( array() );
|
||||
|
||||
remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
|
||||
|
||||
@@ -546,7 +543,7 @@ if ( is_multisite() ) :
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
|
||||
// We manually inserted a non-existing site and overrode the results with it.
|
||||
$this->assertSame( array( 555 ), $q->networks );
|
||||
$this->assertSame( array( 555 ), $results );
|
||||
|
||||
// Make sure manually setting total_users doesn't get overwritten.
|
||||
$this->assertEquals( 1, $q->found_networks );
|
||||
|
||||
@@ -914,6 +914,7 @@ if ( is_multisite() ) :
|
||||
|
||||
/**
|
||||
* @ticket 45749
|
||||
* @ticket 47599
|
||||
*/
|
||||
public function test_sites_pre_query_filter_should_bypass_database_query() {
|
||||
global $wpdb;
|
||||
@@ -923,11 +924,7 @@ if ( is_multisite() ) :
|
||||
$num_queries = $wpdb->num_queries;
|
||||
|
||||
$q = new WP_Site_Query();
|
||||
$results = $q->query(
|
||||
array(
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
$results = $q->query( array() );
|
||||
|
||||
remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
|
||||
|
||||
@@ -935,7 +932,7 @@ if ( is_multisite() ) :
|
||||
$this->assertSame( $num_queries, $wpdb->num_queries );
|
||||
|
||||
// We manually inserted a non-existing site and overrode the results with it.
|
||||
$this->assertSame( array( 555 ), $q->sites );
|
||||
$this->assertSame( array( 555 ), $results );
|
||||
|
||||
// Make sure manually setting total_users doesn't get overwritten.
|
||||
$this->assertEquals( 1, $q->found_sites );
|
||||
|
||||
Reference in New Issue
Block a user