Make WordPress Core


Ignore:
Timestamp:
05/02/2023 10:55:57 AM (3 years ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r55694 r55701  
    76547654        $term_ids = array();
    76557655        if ( $prime_post_terms ) {
    7656                 $prime_term_ids     = array();
    7657                 $prime_taxonomy_ids = array();
    76587656                foreach ( $prime_post_terms as $taxonomy => $post_ids ) {
    76597657                        $cached_term_ids = wp_cache_get_multiple( $post_ids, "{$taxonomy}_relationships" );
     
    76647662                                        foreach ( $_term_ids as $term_id ) {
    76657663                                                if ( is_numeric( $term_id ) ) {
    7666                                                         $prime_term_ids[]                  = (int) $term_id;
    7667                                                         $prime_taxonomy_ids[ $taxonomy ][] = (int) $term_id;
     7664                                                        $term_ids[] = (int) $term_id;
    76687665                                                } elseif ( isset( $term_id->term_id ) ) {
    7669                                                         $prime_taxonomy_ids[ $taxonomy ][] = (int) $term_id->term_id;
    7670                                                         $prime_term_ids[]                  = (int) $term_id->term_id;
     7666                                                        $term_ids[] = (int) $term_id->term_id;
    76717667                                                }
    76727668                                        }
     
    76747670                        }
    76757671                }
    7676 
    7677                 if ( $prime_term_ids ) {
    7678                         $prime_term_ids = array_unique( $prime_term_ids );
    7679                         // Do not prime term meta at this point, let the lazy loader take care of that.
    7680                         _prime_term_caches( $prime_term_ids, false );
    7681 
    7682                         foreach ( $prime_taxonomy_ids as $taxonomy => $_term_ids ) {
    7683                                 foreach ( $_term_ids as $term_id ) {
    7684                                         if ( in_array( $term_id, $term_ids, true ) ) {
    7685                                                 continue;
    7686                                         }
    7687                                         $term = get_term( $term_id, $taxonomy );
    7688                                         if ( is_wp_error( $term ) ) {
    7689                                                 continue;
    7690                                         }
    7691 
    7692                                         $term_ids[] = $term_id;
    7693                                 }
    7694                         }
    7695                 }
     7672                $term_ids = array_unique( $term_ids );
    76967673        }
    76977674
Note: See TracChangeset for help on using the changeset viewer.