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:
@@ -132,6 +132,8 @@ if ( ! function_exists( 'cache_users' ) ) :
|
||||
function cache_users( $user_ids ) {
|
||||
global $wpdb;
|
||||
|
||||
update_meta_cache( 'user', $user_ids );
|
||||
|
||||
$clean = _get_non_cached_ids( $user_ids, 'users' );
|
||||
|
||||
if ( empty( $clean ) ) {
|
||||
@@ -141,13 +143,9 @@ if ( ! function_exists( 'cache_users' ) ) :
|
||||
$list = implode( ',', $clean );
|
||||
|
||||
$users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
|
||||
|
||||
$ids = array();
|
||||
foreach ( $users as $user ) {
|
||||
update_user_caches( $user );
|
||||
$ids[] = $user->ID;
|
||||
}
|
||||
update_meta_cache( 'user', $ids );
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user