From 4bdeb57ac59320cc99d2fcfd00b4700ab56412a0 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Tue, 2 May 2023 10:57:24 +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. Built from https://develop.svn.wordpress.org/trunk@55701 git-svn-id: http://core.svn.wordpress.org/trunk@55213 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 29 +++-------------------------- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 9ddf3d96b2..112ba52b7b 100644 --- a/wp-includes/post.php +++ b/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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index fd6039b99c..75015bfef9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.