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:
Jonny Harris
2022-06-10 13:37:52 +00:00
parent f52d476bc6
commit aff6a79b27
5 changed files with 54 additions and 4 deletions
+3
View File
@@ -3434,6 +3434,9 @@ class WP_Query {
*/
public function the_post() {
global $post;
if ( ! $this->in_the_loop ) {
update_post_author_caches( $this->posts );
}
$this->in_the_loop = true;
if ( -1 == $this->current_post ) { // Loop has just started.