mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Cache results in get_objects_in_term().
This helps to reduce database queries when generating nav menus. Props spacedmonkey. Fixes #37094. git-svn-id: https://develop.svn.wordpress.org/trunk@40921 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -291,6 +291,75 @@ class Tests_Taxonomy extends WP_UnitTestCase {
|
||||
$this->assertEquals( array_reverse( $posts_with_tag ), get_objects_in_term( $tag_id, 'post_tag', array( 'order' => 'desc' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37094
|
||||
*/
|
||||
public function test_term_assignment_should_invalidate_get_objects_in_term_cache() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$posts = self::factory()->post->create_many( 2 );
|
||||
$term_id = self::factory()->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
) );
|
||||
|
||||
wp_set_object_terms( $posts[1], $term_id, 'wptests_tax' );
|
||||
|
||||
// Prime cache.
|
||||
$before = get_objects_in_term( $term_id, 'wptests_tax' );
|
||||
$this->assertEqualSets( array( $posts[1] ), $before );
|
||||
|
||||
wp_set_object_terms( $posts[1], array(), 'wptests_tax' );
|
||||
|
||||
$after = get_objects_in_term( $term_id, 'wptests_tax' );
|
||||
$this->assertSame( array(), $after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37094
|
||||
*/
|
||||
public function test_term_deletion_should_invalidate_get_objects_in_term_cache() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$posts = self::factory()->post->create_many( 2 );
|
||||
$term_id = self::factory()->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
) );
|
||||
|
||||
wp_set_object_terms( $posts[1], $term_id, 'wptests_tax' );
|
||||
|
||||
// Prime cache.
|
||||
$before = get_objects_in_term( $term_id, 'wptests_tax' );
|
||||
$this->assertEqualSets( array( $posts[1] ), $before );
|
||||
|
||||
wp_delete_term( $term_id, 'wptests_tax' );
|
||||
|
||||
$after = get_objects_in_term( $term_id, 'wptests_tax' );
|
||||
$this->assertSame( array(), $after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37094
|
||||
*/
|
||||
public function test_post_deletion_should_invalidate_get_objects_in_term_cache() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$posts = self::factory()->post->create_many( 2 );
|
||||
$term_id = self::factory()->term->create( array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
) );
|
||||
|
||||
wp_set_object_terms( $posts[1], $term_id, 'wptests_tax' );
|
||||
|
||||
// Prime cache.
|
||||
$before = get_objects_in_term( $term_id, 'wptests_tax' );
|
||||
$this->assertEqualSets( array( $posts[1] ), $before );
|
||||
|
||||
wp_delete_post( $posts[1], true );
|
||||
|
||||
$after = get_objects_in_term( $term_id, 'wptests_tax' );
|
||||
$this->assertSame( array(), $after );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 25706
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user