From 23d0c953d28e68ab1977177e19c62ae4c37b6917 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 30 May 2016 04:10:16 +0000 Subject: [PATCH] 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 --- src/wp-includes/taxonomy.php | 7 ----- tests/phpunit/tests/term/wpUpdateTerm.php | 34 ----------------------- 2 files changed, 41 deletions(-) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index c255962210..e910e33cc5 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -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. * diff --git a/tests/phpunit/tests/term/wpUpdateTerm.php b/tests/phpunit/tests/term/wpUpdateTerm.php index 4d9d17b8bd..b4c88a71d9 100644 --- a/tests/phpunit/tests/term/wpUpdateTerm.php +++ b/tests/phpunit/tests/term/wpUpdateTerm.php @@ -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,