WordPress.org

Make WordPress Core

Ticket #21760: 21760.13.diff

File 21760.13.diff, 4.1 KB (added by tollmanz, 6 years ago)
  • src/wp-includes/taxonomy.php

    diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
    index e967503..d2ee5a0 100644
    function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { 
    13021302                        $term = $term->term_id;
    13031303                if ( !$term = (int) $term )
    13041304                        return null;
    1305                 if ( ! $_term = wp_cache_get($term, $taxonomy) ) {
     1305                if ( ! $_term = wp_cache_get($term, $taxonomy . ':terms:' . $incrementor) ) {
    13061306                        $_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) );
    13071307                        if ( ! $_term )
    13081308                                return null;
  • tests/phpunit/tests/term/cache.php

    diff --git tests/phpunit/tests/term/cache.php tests/phpunit/tests/term/cache.php
    index b6962ce..6b4ae9c 100644
    class Tests_Term_Cache extends WP_UnitTestCase { 
    108108                $term = get_term_by( 'slug', 'burrito', 'post_tag' );
    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:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
    112112
    113113                $this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
    114114                $this->assertEquals( $initial, $wpdb->num_queries );
    class Tests_Term_Cache extends WP_UnitTestCase { 
    128128                $term = get_term_by( 'slug', 'burrito', 'post_tag' );
    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:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
    132132
    133133                wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) );
    134134                $this->assertNotEquals( $term, get_term( $term_id, 'post_tag' ) );
    class Tests_Term_Cache extends WP_UnitTestCase { 
    183183                $slug = '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 = $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 . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
     197                $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) );
     198                $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) );
    200199
    201200                wp_suspend_cache_invalidation();
    202201                clean_term_cache( $term_id, $taxonomy );
    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 . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
     205                $this->assertEquals( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) );
     206                $this->assertEquals( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) );
    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->assertEquals( $last_changed, wp_cache_get( 'last_changed', 'terms' ) );
    211210        }
    212211}
     212 No newline at end of file