Make WordPress Core

Changeset 35117


Ignore:
Timestamp:
10/13/2015 02:57:21 AM (8 years ago)
Author:
boonebgorges
Message:

In get_terms(), don't store WP_Term objects in cache.

Fixes #34282.

Location:
trunk
Files:
2 edited

Legend:

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

    r35032 r35117  
    11561156    $cache = wp_cache_get( $cache_key, 'terms' );
    11571157    if ( false !== $cache ) {
     1158        if ( 'all' === $args['fields'] ) {
     1159            $cache = array_map( 'get_term', $cache );
     1160        }
    11581161
    11591162        /**
     
    14951498            $_terms[ $term->term_id ] = $term->slug;
    14961499        }
    1497     } else {
    1498         $_terms = array_map( 'get_term', $terms );
    14991500    }
    15001501
     
    15081509
    15091510    wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS );
     1511
     1512    if ( 'all' === $_fields ) {
     1513        $terms = array_map( 'get_term', $terms );
     1514    }
    15101515
    15111516    /** This filter is documented in wp-includes/taxonomy */
  • trunk/tests/phpunit/tests/term/getTerms.php

    r34998 r35117  
    15941594    /**
    15951595     * @ticket 14162
     1596     * @ticket 34282
     1597     */
     1598    public function test_should_return_wp_term_objects_when_pulling_from_the_cache() {
     1599        global $wpdb;
     1600
     1601        register_taxonomy( 'wptests_tax', 'post' );
     1602        $terms = $this->factory->term->create_many( 2, array( 'taxonomy' => 'wptests_tax' ) );
     1603
     1604        // Prime the cache.
     1605        get_terms( 'wptests_tax', array(
     1606            'hide_empty' => false,
     1607            'fields' => 'all',
     1608        ) );
     1609
     1610        $num_queries = $wpdb->num_queries;
     1611
     1612        $found = get_terms( 'wptests_tax', array(
     1613            'hide_empty' => false,
     1614            'fields' => 'all',
     1615        ) );
     1616
     1617        $this->assertSame( $num_queries, $wpdb->num_queries );
     1618
     1619        $this->assertNotEmpty( $found );
     1620
     1621        foreach ( $found as $term ) {
     1622            $this->assertInstanceOf( 'WP_Term', $term );
     1623        }
     1624    }
     1625
     1626    /**
     1627     * @ticket 14162
    15961628     */
    15971629    public function test_should_prime_individual_term_cache_when_fields_is_all() {
Note: See TracChangeset for help on using the changeset viewer.