Make WordPress Core

Changeset 37593


Ignore:
Timestamp:
05/30/2016 04:10:16 AM (8 years ago)
Author:
boonebgorges
Message:

Don't clear object relationship caches on term update.

Since [37573], object relationship caches ({$taxonomy}_relationships)
contain term IDs rather than term objects. See #36814. As such, it's no longer
necessary to clear these caches when a term is updated; none of the data that's
changed on update (name, description, count, etc) is stored in the relationship
cache.

Fixes #36251.

Location:
trunk
Files:
2 edited

Legend:

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

    r37578 r37593  
    29492949    do_action( 'edited_term_taxonomy', $tt_id, $taxonomy );
    29502950
    2951     // Clean the relationship caches for all object types using this term.
    2952     $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );
    2953     $tax_object = get_taxonomy( $taxonomy );
    2954     foreach ( $tax_object->object_type as $object_type ) {
    2955         clean_object_term_cache( $objects, $object_type );
    2956     }
    2957 
    29582951    /**
    29592952     * Fires after a term has been updated, but before the term cache has been cleaned.
  • trunk/tests/phpunit/tests/term/wpUpdateTerm.php

    r35242 r37593  
    487487        $this->assertInternalType( 'int', $found['term_id'] );
    488488        $this->assertInternalType( 'int', $found['term_taxonomy_id'] );
    489     }
    490 
    491     public function test_wp_update_term_should_clean_object_term_cache() {
    492         register_taxonomy( 'wptests_tax_for_post', 'post' );
    493         register_taxonomy( 'wptests_tax_for_page', 'page' );
    494         $post = self::factory()->post->create();
    495         $page = self::factory()->post->create( array(
    496             'post_type' => 'page',
    497         ) );
    498 
    499         $t_for_post = self::factory()->term->create( array(
    500             'taxonomy' => 'wptests_tax_for_post',
    501         ) );
    502         $t_for_page = self::factory()->term->create( array(
    503             'taxonomy' => 'wptests_tax_for_page',
    504         ) );
    505 
    506         wp_set_post_terms( $post, array( $t_for_post ), 'wptests_tax_for_post' );
    507         wp_set_post_terms( $page, array( $t_for_page ), 'wptests_tax_for_page' );
    508 
    509         // Prime caches and verify.
    510         update_object_term_cache( array( $post ), 'post' );
    511         update_object_term_cache( array( $page ), 'page' );
    512         $this->assertNotEmpty( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );
    513         $this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );
    514 
    515         // Update a term in just one of the taxonomies.
    516         $found = wp_update_term( $t_for_post, 'wptests_tax_for_post', array(
    517             'slug' => 'foo',
    518         ) );
    519 
    520         // Only the relevant cache should have been cleared.
    521         $this->assertFalse( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );
    522         $this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );
    523489    }
    524490
Note: See TracChangeset for help on using the changeset viewer.