From 9ef194bc4b9bfaf359f1208dfe927b6688c299f0 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 2 May 2023 10:55:57 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@55701 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 9ddf3d96b2..112ba52b7b 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -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 );