Make WordPress Core

Changeset 55759


Ignore:
Timestamp:
05/16/2023 12:29:34 PM (13 months ago)
Author:
spacedmonkey
Message:

Taxonomy: Do not prime term meta in wp_get_object_terms.

Passing update_term_meta_cache argument value false by default resulting in get_terms to not prime the term meta cache in wp_get_object_terms. Priming of term meta is not needed in this context.

Props spacedmonkey, rutviksavsani.
Fixes #57701.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r55703 r55759  
    21932193 *              'all_with_object_id', an array of `WP_Term` objects will be returned.
    21942194 * @since 4.7.0 Refactored to use WP_Term_Query, and to support any WP_Term_Query arguments.
     2195 * @since 6.3.0 Passing `update_term_meta_cache` argument value false by default resulting in get_terms() to not
     2196 *              prime the term meta cache.
    21952197 *
    21962198 * @param int|int[]       $object_ids The ID(s) of the object(s) to retrieve.
     
    22212223    $object_ids = array_map( 'intval', $object_ids );
    22222224
    2223     $args = wp_parse_args( $args );
     2225    $defaults = array(
     2226        'update_term_meta_cache' => false,
     2227    );
     2228
     2229    $args = wp_parse_args( $args, $defaults );
    22242230
    22252231    /**
  • trunk/tests/phpunit/tests/term/getTheTerms.php

    r55745 r55759  
    196196    /**
    197197     * @ticket 36814
    198      */
    199     public function test_uncached_terms_should_be_primed_with_a_single_query() {
     198     * @ticket 57701
     199     */
     200    public function test_uncached_terms_should_not_be_primed_with_a_single_query_by_default() {
    200201        register_taxonomy( 'wptests_tax', 'post' );
    201202
     
    214215        $this->assertSameSets( $terms, wp_list_pluck( $found, 'term_id' ) );
    215216
    216         $num_queries++;
    217         $this->assertSame( $num_queries, get_num_queries() );
    218 
     217        // Two extra queries are expected as the cache is not primed and hence terms need to be queried.
     218        $this->assertSame( 1, get_num_queries() - $num_queries );
    219219    }
    220220
  • trunk/tests/phpunit/tests/term/wpGetObjectTerms.php

    r55745 r55759  
    615615    /**
    616616     * @ticket 10142
    617      */
    618     public function test_termmeta_cache_should_be_lazy_loaded_by_default() {
     617     * @ticket 57701
     618     */
     619    public function test_termmeta_cache_should_not_be_lazy_loaded_by_default() {
    619620        register_taxonomy( 'wptests_tax', 'post' );
    620621        $terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
     
    634635        }
    635636
    636         $this->assertSame( $num_queries + 1, get_num_queries() );
     637        // Here we had extra queries as the term meta cache was not primed by default.
     638        $this->assertSame( 3, get_num_queries() - $num_queries );
    637639    }
    638640
Note: See TracChangeset for help on using the changeset viewer.