WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/12/2019 10:16:08 PM (2 years ago)
Author:
adamsilverstein
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/networkQuery.php

    r44983 r46100  
    526526        /**
    527527         * @ticket 45749
     528         * @ticket 47599
    528529         */
    529530        public function test_networks_pre_query_filter_should_bypass_database_query() {
     
    535536
    536537            $q       = new WP_Network_Query();
    537             $results = $q->query(
    538                 array(
    539                     'fields' => 'ids',
    540                 )
    541             );
     538            $results = $q->query( array() );
    542539
    543540            remove_filter( 'networks_pre_query', array( __CLASS__, 'filter_networks_pre_query' ), 10, 2 );
     
    547544
    548545            // We manually inserted a non-existing site and overrode the results with it.
    549             $this->assertSame( array( 555 ), $q->networks );
     546            $this->assertSame( array( 555 ), $results );
    550547
    551548            // Make sure manually setting total_users doesn't get overwritten.
Note: See TracChangeset for help on using the changeset viewer.