mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Taxonomy: Do not prime term meta in wp_get_object_terms.
Passing `update_term_meta_cache` argument value false by default resulting in `get_terms` to not prime the term meta cache in `wp_get_object_terms`. Priming of term meta is not needed in this context. Props spacedmonkey, rutviksavsani. Fixes #57701. git-svn-id: https://develop.svn.wordpress.org/trunk@55759 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2192,6 +2192,8 @@ function wp_delete_category( $cat_id ) {
|
||||
* @since 4.4.0 Introduced `$meta_query` and `$update_term_meta_cache` arguments. When `$fields` is 'all' or
|
||||
* 'all_with_object_id', an array of `WP_Term` objects will be returned.
|
||||
* @since 4.7.0 Refactored to use WP_Term_Query, and to support any WP_Term_Query arguments.
|
||||
* @since 6.3.0 Passing `update_term_meta_cache` argument value false by default resulting in get_terms() to not
|
||||
* prime the term meta cache.
|
||||
*
|
||||
* @param int|int[] $object_ids The ID(s) of the object(s) to retrieve.
|
||||
* @param string|string[] $taxonomies The taxonomy names to retrieve terms from.
|
||||
@@ -2220,7 +2222,11 @@ function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) {
|
||||
}
|
||||
$object_ids = array_map( 'intval', $object_ids );
|
||||
|
||||
$args = wp_parse_args( $args );
|
||||
$defaults = array(
|
||||
'update_term_meta_cache' => false,
|
||||
);
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
/**
|
||||
* Filters arguments for retrieving object terms.
|
||||
|
||||
@@ -195,8 +195,9 @@ class Tests_Term_GetTheTerms extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 36814
|
||||
* @ticket 57701
|
||||
*/
|
||||
public function test_uncached_terms_should_be_primed_with_a_single_query() {
|
||||
public function test_uncached_terms_should_not_be_primed_with_a_single_query_by_default() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
@@ -213,9 +214,8 @@ class Tests_Term_GetTheTerms extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSameSets( $terms, wp_list_pluck( $found, 'term_id' ) );
|
||||
|
||||
$num_queries++;
|
||||
$this->assertSame( $num_queries, get_num_queries() );
|
||||
|
||||
// Two extra queries are expected as the cache is not primed and hence terms need to be queried.
|
||||
$this->assertSame( 1, get_num_queries() - $num_queries );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -614,8 +614,9 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* @ticket 10142
|
||||
* @ticket 57701
|
||||
*/
|
||||
public function test_termmeta_cache_should_be_lazy_loaded_by_default() {
|
||||
public function test_termmeta_cache_should_not_be_lazy_loaded_by_default() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
$terms = self::factory()->term->create_many( 3, array( 'taxonomy' => 'wptests_tax' ) );
|
||||
add_term_meta( $terms[0], 'foo', 'bar' );
|
||||
@@ -633,7 +634,8 @@ class Tests_Term_WpGetObjectTerms extends WP_UnitTestCase {
|
||||
$this->assertSame( 'bar', get_term_meta( $t, 'foo', true ) );
|
||||
}
|
||||
|
||||
$this->assertSame( $num_queries + 1, get_num_queries() );
|
||||
// Here we had extra queries as the term meta cache was not primed by default.
|
||||
$this->assertSame( 3, get_num_queries() - $num_queries );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user