Remove caching for get_term_by() calls.

The new cache group scheme causes term invalidation to be overly broad, so
that busting the cache for one term will bust the cache for all terms in the
taxonomy. We'll have another go at more focused use of the 'last_changed'
incrementor in a future release.

Reverts [29915], [30073], [30080], [30108], [30112].
See #21760.

git-svn-id: https://develop.svn.wordpress.org/trunk@30900 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2014-12-16 13:26:19 +00:00
parent 3a63ae0cb2
commit bf62165353
2 changed files with 12 additions and 169 deletions

View File

@@ -93,122 +93,4 @@ class Tests_Term_Cache extends WP_UnitTestCase {
_unregister_taxonomy( $tax );
}
/**
* @ticket 21760
*/
function test_get_term_by_slug_cache() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'taxonomy' => 'post_tag' ) );
$queries = $wpdb->num_queries;
get_term_by( 'slug', 'burrito', 'post_tag' );
$initial = $queries + 1;
$this->assertEquals( $initial, $wpdb->num_queries );
$term = get_term_by( 'slug', 'burrito', 'post_tag' );
$this->assertEquals( $initial, $wpdb->num_queries );
$this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
$this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
$this->assertEquals( $initial, $wpdb->num_queries );
}
/**
* @ticket 21760
*/
function test_get_term_by_slug_cache_update() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'taxonomy' => 'post_tag' ) );
$queries = $wpdb->num_queries;
get_term_by( 'slug', 'burrito', 'post_tag' );
$initial = $queries + 1;
$this->assertEquals( $initial, $wpdb->num_queries );
$term = get_term_by( 'slug', 'burrito', 'post_tag' );
$this->assertEquals( $initial, $wpdb->num_queries );
$this->assertEquals( $term, wp_cache_get( $term_id, 'post_tag:terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
wp_update_term( $term_id, 'post_tag', array( 'name' => 'Taco' ) );
$this->assertNotEquals( $term, get_term( $term_id, 'post_tag' ) );
$after_queries = $wpdb->num_queries;
get_term_by( 'slug', 'burrito', 'post_tag' );
$this->assertEquals( $after_queries, $wpdb->num_queries );
}
/**
* @ticket 21760
*/
function test_get_term_by_name_cache() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'name' => 'burrito', 'taxonomy' => 'post_tag' ) );
$queries = $wpdb->num_queries;
get_term_by( 'name', 'burrito', 'post_tag' );
$initial = $queries + 1;
$this->assertEquals( $initial, $wpdb->num_queries );
$term = get_term_by( 'name', 'burrito', 'post_tag' );
$this->assertEquals( $initial, $wpdb->num_queries );
$this->assertEquals( get_term( $term_id, 'post_tag' ), $term );
$this->assertEquals( $initial, $wpdb->num_queries );
}
/**
* @ticket 21760
*/
function test_get_term_by_name_cache_update() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'name' => 'burrito', 'taxonomy' => 'post_tag' ) );
$queries = $wpdb->num_queries;
get_term_by( 'name', 'burrito', 'post_tag' );
$initial = $queries + 1;
$this->assertEquals( $initial, $wpdb->num_queries );
$term = get_term_by( 'name', 'burrito', 'post_tag' );
$this->assertEquals( $initial, $wpdb->num_queries );
wp_update_term( $term_id, 'post_tag', array( 'slug' => 'Taco' ) );
$this->assertNotEquals( $term, get_term( $term_id, 'post_tag' ) );
$after_queries = $wpdb->num_queries;
get_term_by( 'name', 'burrito', 'post_tag' );
$this->assertEquals( $after_queries, $wpdb->num_queries );
}
/**
* @ticket 21760
*/
function test_invalidating_term_caches_should_fail_when_invalidation_is_suspended() {
$slug = 'taco';
$name = 'Taco';
$taxonomy = 'post_tag';
$cache_key_slug = $slug;
$cache_key_name = $name;
$term_id = $this->factory->term->create( array( 'slug' => $slug, 'name' => $name, 'taxonomy' => $taxonomy ) );
$last_changed = wp_cache_get( 'last_changed', 'terms' );
$term = get_term_by( 'slug', $slug, $taxonomy );
// Verify the term is cached by ID, slug and name
$this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
$this->assertSame( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) );
$this->assertSame( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) );
$suspend = wp_suspend_cache_invalidation();
clean_term_cache( $term_id, $taxonomy );
// Verify that the cached value still matches the correct value
$this->assertEquals( $term, wp_cache_get( $term_id, $taxonomy . ':terms:' . wp_cache_get( 'last_changed', 'terms' ) ) );
$this->assertSame( $term_id, wp_cache_get( $cache_key_slug, $taxonomy . ':slugs:' . wp_cache_get( 'last_changed', 'terms' ) ) );
$this->assertSame( $term_id, wp_cache_get( $cache_key_name, $taxonomy . ':names:' . wp_cache_get( 'last_changed', 'terms' ) ) );
// Verify that last changed has not been updated as part of an invalidation routine
$this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'terms' ) );
// Clean up.
wp_suspend_cache_invalidation( $suspend );
}
}