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.

git-svn-id: https://develop.svn.wordpress.org/trunk@37593 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-05-30 04:10:16 +00:00
parent 8e79f0fb3d
commit 23d0c953d2
2 changed files with 0 additions and 41 deletions

View File

@ -2948,13 +2948,6 @@ function wp_update_term( $term_id, $taxonomy, $args = array() ) {
*/
do_action( 'edited_term_taxonomy', $tt_id, $taxonomy );
// Clean the relationship caches for all object types using this term.
$objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );
$tax_object = get_taxonomy( $taxonomy );
foreach ( $tax_object->object_type as $object_type ) {
clean_object_term_cache( $objects, $object_type );
}
/**
* Fires after a term has been updated, but before the term cache has been cleaned.
*

View File

@ -488,40 +488,6 @@ class Tests_Term_WpUpdateTerm extends WP_UnitTestCase {
$this->assertInternalType( 'int', $found['term_taxonomy_id'] );
}
public function test_wp_update_term_should_clean_object_term_cache() {
register_taxonomy( 'wptests_tax_for_post', 'post' );
register_taxonomy( 'wptests_tax_for_page', 'page' );
$post = self::factory()->post->create();
$page = self::factory()->post->create( array(
'post_type' => 'page',
) );
$t_for_post = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax_for_post',
) );
$t_for_page = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax_for_page',
) );
wp_set_post_terms( $post, array( $t_for_post ), 'wptests_tax_for_post' );
wp_set_post_terms( $page, array( $t_for_page ), 'wptests_tax_for_page' );
// Prime caches and verify.
update_object_term_cache( array( $post ), 'post' );
update_object_term_cache( array( $page ), 'page' );
$this->assertNotEmpty( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );
$this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );
// Update a term in just one of the taxonomies.
$found = wp_update_term( $t_for_post, 'wptests_tax_for_post', array(
'slug' => 'foo',
) );
// Only the relevant cache should have been cleared.
$this->assertFalse( wp_cache_get( $post, 'wptests_tax_for_post_relationships' ) );
$this->assertNotEmpty( wp_cache_get( $page, 'wptests_tax_for_page_relationships' ) );
}
public function test_wp_update_term_should_clean_term_cache() {
register_taxonomy( 'wptests_tax', 'post', array(
'hierarchical' => true,