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/siteQuery.php

    r44983 r46100  
    915915        /**
    916916         * @ticket 45749
     917         * @ticket 47599
    917918         */
    918919        public function test_sites_pre_query_filter_should_bypass_database_query() {
     
    924925
    925926            $q       = new WP_Site_Query();
    926             $results = $q->query(
    927                 array(
    928                     'fields' => 'ids',
    929                 )
    930             );
     927            $results = $q->query( array() );
    931928
    932929            remove_filter( 'sites_pre_query', array( __CLASS__, 'filter_sites_pre_query' ), 10, 2 );
     
    936933
    937934            // We manually inserted a non-existing site and overrode the results with it.
    938             $this->assertSame( array( 555 ), $q->sites );
     935            $this->assertSame( array( 555 ), $results );
    939936
    940937            // Make sure manually setting total_users doesn't get overwritten.
Note: See TracChangeset for help on using the changeset viewer.