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.
Built from https://develop.svn.wordpress.org/trunk@54894


git-svn-id: http://core.svn.wordpress.org/trunk@54446 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2022-11-29 20:29:11 +00:00
parent 3ba44120d0
commit 15d01c9235
2 changed files with 18 additions and 3 deletions

View File

@ -7876,7 +7876,9 @@ function _update_term_count_on_transition_post_status( $new_status, $old_status,
* @since 3.4.0
* @since 6.1.0 This function is no longer marked as "private".
*
* @see update_post_caches()
* @see update_post_cache()
* @see update_postmeta_cache()
* @see update_object_term_cache()
*
* @global wpdb $wpdb WordPress database abstraction object.
*
@ -7891,7 +7893,20 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache
if ( ! empty( $non_cached_ids ) ) {
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) );
update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
if ( $fresh_posts ) {
// Despite the name, update_post_cache() expects an array rather than a single post.
update_post_cache( $fresh_posts );
}
}
if ( $update_meta_cache ) {
update_postmeta_cache( $ids );
}
if ( $update_term_cache ) {
$post_types = array_map( 'get_post_type', $ids );
$post_types = array_unique( $post_types );
update_object_term_cache( $ids, $post_types );
}
}

View File

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