Make WordPress Core


Ignore:
Timestamp:
10/16/2017 06:34:29 PM (9 years ago)
Author:
boonebgorges
Message:

Don't force distinct term queries when specifying number and object_ids.

This reverts [41377], which caused performance problems on sites with a large
number of terms.

See #41796.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/query.php

    r41809 r41880  
    472472                $this->assertSame( $expected, $found3 );
    473473        }
    474 
    475         /**
    476          * @ticket 41796
    477          */
    478         public function test_number_should_work_with_object_ids() {
    479                 register_taxonomy( 'wptests_tax', 'post' );
    480 
    481                 $term_1 = self::factory()->term->create( array(
    482                         'taxonomy' => 'wptests_tax',
    483                 ) );
    484                 $term_2 = self::factory()->term->create( array(
    485                         'taxonomy' => 'wptests_tax',
    486                 ) );
    487 
    488                 $post_1 = self::factory()->post->create();
    489                 $post_2 = self::factory()->post->create();
    490 
    491                 wp_set_object_terms( $post_1, array( $term_1, $term_2 ), 'wptests_tax' );
    492                 wp_set_object_terms( $post_2, array( $term_1 ), 'wptests_tax' );
    493 
    494                 $q = new WP_Term_Query( array(
    495                         'taxonomy' => 'wptests_tax',
    496                         'object_ids' => array( $post_1, $post_2 ),
    497                         'number' => 2,
    498                 ) );
    499 
    500                 $this->assertEqualSets( array( $term_1, $term_2 ), wp_list_pluck( $q->terms, 'term_id' ) );
    501         }
    502 
    503         /**
    504          * @ticket 41796
    505          */
    506         public function test_number_should_work_with_object_ids_and_all_with_object_id() {
    507                 register_taxonomy( 'wptests_tax', 'post' );
    508 
    509                 $term_1 = self::factory()->term->create( array(
    510                         'taxonomy' => 'wptests_tax',
    511                 ) );
    512                 $term_2 = self::factory()->term->create( array(
    513                         'taxonomy' => 'wptests_tax',
    514                 ) );
    515 
    516                 $post_1 = self::factory()->post->create();
    517                 $post_2 = self::factory()->post->create();
    518 
    519                 wp_set_object_terms( $post_1, array( $term_1, $term_2 ), 'wptests_tax' );
    520                 wp_set_object_terms( $post_2, array( $term_1 ), 'wptests_tax' );
    521 
    522                 $q = new WP_Term_Query( array(
    523                         'taxonomy' => 'wptests_tax',
    524                         'object_ids' => array( $post_1, $post_2 ),
    525                         'fields' => 'all_with_object_id',
    526                         'number' => 2,
    527                 ) );
    528 
    529                 $this->assertEqualSets( array( $term_1, $term_1 ), wp_list_pluck( $q->terms, 'term_id' ) );
    530         }
    531474}
Note: See TracChangeset for help on using the changeset viewer.