Taxonomy: Remove redundant call to get_term in wp_queue_posts_for_term_meta_lazyload.

In [55252] the function `wp_queue_posts_for_term_meta_lazyload` was refactored to use `wp_cache_get_multiple`. This refactor included a call to `get_term`. However, calling get_term calls `sanitize_term`, which sanitizes all fields in a term. The full term object is not needed in this context as term meta only needs to the term id, which is already in the function. Saving calls to `sanitize_term` will improve performance of this function. 

Props spacedmonkey, joemcgill, mukesh27. 
Fixes #57966.
Built from https://develop.svn.wordpress.org/trunk@55701


git-svn-id: http://core.svn.wordpress.org/trunk@55213 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2023-05-02 10:57:24 +00:00
parent fe8c41f574
commit 4bdeb57ac5
2 changed files with 4 additions and 27 deletions

View File

@ -7653,8 +7653,6 @@ function wp_queue_posts_for_term_meta_lazyload( $posts ) {
$term_ids = array();
if ( $prime_post_terms ) {
$prime_term_ids = array();
$prime_taxonomy_ids = array();
foreach ( $prime_post_terms as $taxonomy => $post_ids ) {
$cached_term_ids = wp_cache_get_multiple( $post_ids, "{$taxonomy}_relationships" );
if ( is_array( $cached_term_ids ) ) {
@ -7663,36 +7661,15 @@ function wp_queue_posts_for_term_meta_lazyload( $posts ) {
// Backward compatibility for if a plugin is putting objects into the cache, rather than IDs.
foreach ( $_term_ids as $term_id ) {
if ( is_numeric( $term_id ) ) {
$prime_term_ids[] = (int) $term_id;
$prime_taxonomy_ids[ $taxonomy ][] = (int) $term_id;
$term_ids[] = (int) $term_id;
} elseif ( isset( $term_id->term_id ) ) {
$prime_taxonomy_ids[ $taxonomy ][] = (int) $term_id->term_id;
$prime_term_ids[] = (int) $term_id->term_id;
$term_ids[] = (int) $term_id->term_id;
}
}
}
}
}
if ( $prime_term_ids ) {
$prime_term_ids = array_unique( $prime_term_ids );
// Do not prime term meta at this point, let the lazy loader take care of that.
_prime_term_caches( $prime_term_ids, false );
foreach ( $prime_taxonomy_ids as $taxonomy => $_term_ids ) {
foreach ( $_term_ids as $term_id ) {
if ( in_array( $term_id, $term_ids, true ) ) {
continue;
}
$term = get_term( $term_id, $taxonomy );
if ( is_wp_error( $term ) ) {
continue;
}
$term_ids[] = $term_id;
}
}
}
$term_ids = array_unique( $term_ids );
}
wp_lazyload_term_meta( $term_ids );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-55700';
$wp_version = '6.3-alpha-55701';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.