mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Prime users cache in WP_Query and post REST API controller.
For a call to `WP_Query` or a post REST API request that contains posts from multiple authors, call the `cache_users` function, to ensure that all user data for post authors is primed in a single database query. This results in far fewer database queries on multiple author sites. Props spacedmonkey, timothyblynjacobs, peterwilsoncc. Fixes #55716. git-svn-id: https://develop.svn.wordpress.org/trunk@53482 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -7474,6 +7474,20 @@ function update_post_caches( &$posts, $post_type = 'post', $update_term_cache =
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prime post author user caches.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param WP_Post[] $posts Array of Post objects
|
||||
*/
|
||||
function update_post_author_caches( $posts ) {
|
||||
$author_ids = wp_list_pluck( $posts, 'post_author' );
|
||||
$author_ids = array_map( 'absint', $author_ids );
|
||||
$author_ids = array_unique( array_filter( $author_ids ) );
|
||||
cache_users( $author_ids );
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates metadata cache for list of post IDs.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user