mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@54894 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user