mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Add cache invalidation when updating a term, example: create a category, assign it to a post, edit the category. Currently, the post's term cache is not updated. When updating terms in a given taxonomy, invalidate the object term caches linked to that taxonomy.
Introduce `get_taxonomy_last_changed()`, `set_taxonomy_last_changed()`, and `post_taxonomy_is_fresh()`.
`post_taxonomy_is_fresh()` is only called in `get_object_term_cache()` - at which point the taxonomy's `last_changed` value is checked against the post's `{$taxonomy}_last_changed` value.
`set_taxonomy_last_changed()` is called whenever directory database queries are made that insert new terms or affect existing terms.
Fixes #22526.
git-svn-id: https://develop.svn.wordpress.org/trunk@27101 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -568,6 +568,56 @@ class Tests_Term extends WP_UnitTestCase {
|
||||
$this->assertEquals( 0, $count );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 22526
|
||||
*/
|
||||
function test_get_taxonomy_last_changed() {
|
||||
$last_changed = get_taxonomy_last_changed( 'category' );
|
||||
$last_changed_cache = wp_cache_get( 'last_changed', 'category' );
|
||||
$this->assertEquals( $last_changed, $last_changed_cache );
|
||||
wp_cache_delete( 'last_changed', 'category' );
|
||||
$this->assertEquals( $last_changed, $last_changed_cache );
|
||||
$last_changed = get_taxonomy_last_changed( 'category' );
|
||||
$this->assertNotEquals( $last_changed, $last_changed_cache );
|
||||
|
||||
$last_changed2 = get_taxonomy_last_changed( 'category' );
|
||||
$this->factory->category->create();
|
||||
$last_changed3 = get_taxonomy_last_changed( 'category' );
|
||||
$this->assertNotEquals( $last_changed2, $last_changed3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 22526
|
||||
*/
|
||||
function test_set_taxonomy_last_changed() {
|
||||
$last_changed1 = set_taxonomy_last_changed( 'category' );
|
||||
$last_changed2 = set_taxonomy_last_changed( 'category' );
|
||||
$this->assertNotEquals( $last_changed1, $last_changed2 );
|
||||
|
||||
$last_changed3 = set_taxonomy_last_changed( 'category' );
|
||||
$last_changed4 = get_taxonomy_last_changed( 'category' );
|
||||
$this->assertEquals( $last_changed3, $last_changed4 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 22526
|
||||
*/
|
||||
function test_post_taxonomy_is_fresh() {
|
||||
$post_id = $this->factory->post->create();
|
||||
$term_id = $this->factory->category->create( array( 'name' => 'Foo' ) );
|
||||
wp_set_post_categories( $post_id, $term_id );
|
||||
|
||||
$this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) );
|
||||
$this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );
|
||||
$this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );
|
||||
|
||||
wp_update_term( $term_id, 'category', array( 'name' => 'Bar' ) );
|
||||
|
||||
$this->assertFalse( post_taxonomy_is_fresh( $post_id, 'category' ) );
|
||||
get_the_category( $post_id );
|
||||
$this->assertTrue( post_taxonomy_is_fresh( $post_id, 'category' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 22526
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user