Make WordPress Core


Ignore:
Timestamp:
11/29/2022 08:27:29 PM (3 years ago)
Author:
ocean90
Message:

Query: Account for primed post caches without primed post meta/term caches.

In [54352] update_post_caches() was replaced by _prime_post_caches() to reduce excessive object cache calls. That's because _prime_post_caches() checks first if post IDs aren't already cached. Unfortunately this becomes an issue if a post itself is cached but not the meta/terms.
To fix this regression, _prime_post_caches() now always calls update_postmeta_cache() and update_object_term_cache() depending on the arguments passed to it. Both functions internally check whether IDs are already cached so the fix from [54352] remains in place.

Props peterwilsoncc, spacedmonkey, ocean90.
Fixes #57163.

File:
1 edited

Legend:

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

    r54891 r54894  
    78777877 * @since 6.1.0 This function is no longer marked as "private".
    78787878 *
    7879  * @see update_post_caches()
     7879 * @see update_post_cache()
     7880 * @see update_postmeta_cache()
     7881 * @see update_object_term_cache()
    78807882 *
    78817883 * @global wpdb $wpdb WordPress database abstraction object.
     
    78927894        $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) );
    78937895
    7894         update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
     7896        if ( $fresh_posts ) {
     7897            // Despite the name, update_post_cache() expects an array rather than a single post.
     7898            update_post_cache( $fresh_posts );
     7899        }
     7900    }
     7901
     7902    if ( $update_meta_cache ) {
     7903        update_postmeta_cache( $ids );
     7904    }
     7905
     7906    if ( $update_term_cache ) {
     7907        $post_types = array_map( 'get_post_type', $ids );
     7908        $post_types = array_unique( $post_types );
     7909        update_object_term_cache( $ids, $post_types );
    78957910    }
    78967911}
Note: See TracChangeset for help on using the changeset viewer.