Make WordPress Core

Changeset 30108

Timestamp:
10/30/2014 02:49:51 AM (10 years ago)
Author:
boonebgorges
Message:

Clean up get_term_by() caching.

  • Fix cache key/group modification that was missed in [30073].
  • Update unit tests to reflect new key/group format.

Props tollmanz.
Fixes #21760.

Location:
trunk
Files:
2 edited

Legend:

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

    r30107 r30108  
    12961296        if ( !$term = (int) $term )
    12971297            return null;
    1298         if ( ! $_term = wp_cache_get($term, $taxonomy) ) {
     1298        if ( ! $_term = wp_cache_get() ) {
    12991299            $_term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND t.term_id = %d LIMIT 1", $taxonomy, $term) );
    13001300            if ( ! $_term )
  • trunk/tests/phpunit/tests/term/cache.php

    r30080 r30108  
    109109        $this->assertEquals( $initial, $wpdb->num_queries );
    110110
    111         $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag' ) );
     111        $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag ) );
    112112
    113113        $this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
     
    129129        $this->assertEquals( $initial, $wpdb->num_queries );
    130130
    131         $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag' ) );
     131        $this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag ) );
    132132
    133133        wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) );
     
    184184        $name = 'Taco';
    185185        $taxonomy = 'post_tag';
    186         $cache_key_slug = 'slug:' . $slug;
    187         $cache_key_name = 'name:' . md5( $name );
     186        $cache_key_slug = $slug;
     187        $cache_key_name = ;
    188188
    189189        $term_id = $this->factory->term->create( array( 'slug' => $slug, 'name' => $name, 'taxonomy' => $taxonomy ) );
    190190
    191191        $last_changed = wp_cache_get( 'last_changed', 'terms' );
    192         $group = $taxonomy . ':' . $last_changed;
    193192
    194193        $term = get_term_by( 'slug', $slug, $taxonomy );
    195194
    196195        // Verify the term is cached by ID, slug and name
    197         $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy ) );
    198         $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $group ) );
    199         $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $group ) );
     196        $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy ) );
     197        $this->assert ) );
     198        $this->assert ) );
    200199
    201200        wp_suspend_cache_invalidation();
     
    203202
    204203        // Verify that the cached value still matches the correct value
    205         $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy ) );
    206         $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $group ) );
    207         $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $group ) );
     204        $this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy ) );
     205        $this->assert ) );
     206        $this->assert ) );
    208207
    209208        // Verify that last changed has not been updated as part of an invalidation routine
    210         $this->assertEquals( $last_changed, wp_get_last_changed( 'terms' ) );
     209        $this->assert 'terms' ) );
    211210    }
    212211}
Note: See TracChangeset for help on using the changeset viewer.