Make WordPress Core


Ignore:
Timestamp:
07/17/2017 08:15:27 PM (8 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

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

    r38102 r41063  
    380380        $this->assertEquals( $expected, $found );
    381381    }
     382
     383    /**
     384     * @ticket 41347
     385     */
     386    public function test_wp_network_query_cache_with_different_fields_no_count() {
     387        global $wpdb;
     388
     389        $q                 = new WP_Network_Query();
     390        $query_1           = $q->query( array(
     391            'fields'     => 'all',
     392            'number'     => 3,
     393            'order'      => 'ASC',
     394        ) );
     395        $number_of_queries = $wpdb->num_queries;
     396
     397        $query_2 = $q->query( array(
     398            'fields'     => 'ids',
     399            'number'     => 3,
     400            'order'      => 'ASC',
     401        ) );
     402
     403        $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     404    }
     405
     406    /**
     407     * @ticket 41347
     408     */
     409    public function test_wp_network_query_cache_with_different_fields_active_count() {
     410        global $wpdb;
     411
     412        $q = new WP_Network_Query();
     413
     414        $query_1           = $q->query( array(
     415            'fields'     => 'all',
     416            'number'     => 3,
     417            'order'      => 'ASC',
     418            'count'      => true,
     419        ) );
     420        $number_of_queries = $wpdb->num_queries;
     421
     422        $query_2 = $q->query( array(
     423            'fields'     => 'ids',
     424            'number'     => 3,
     425            'order'      => 'ASC',
     426            'count'      => true,
     427        ) );
     428        $this->assertEquals( $number_of_queries, $wpdb->num_queries );
     429    }
     430
     431    /**
     432     * @ticket 41347
     433     */
     434    public function test_wp_network_query_cache_with_same_fields_different_count() {
     435        global $wpdb;
     436
     437        $q = new WP_Network_Query();
     438
     439        $query_1 = $q->query( array(
     440            'fields'     => 'ids',
     441            'number'     => 3,
     442            'order'      => 'ASC',
     443        ) );
     444
     445        $number_of_queries = $wpdb->num_queries;
     446
     447        $query_2 = $q->query( array(
     448            'fields'     => 'ids',
     449            'number'     => 3,
     450            'order'      => 'ASC',
     451            'count'      => true,
     452        ) );
     453        $this->assertEquals( $number_of_queries + 1, $wpdb->num_queries );
     454    }
    382455}
    383456
Note: See TracChangeset for help on using the changeset viewer.