Make WordPress Core


Ignore:
Timestamp:
06/10/2022 01:37:52 PM (2 years ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r53480 r53482  
    133133        global $wpdb;
    134134
     135        update_meta_cache( 'user', $user_ids );
     136
    135137        $clean = _get_non_cached_ids( $user_ids, 'users' );
    136138
     
    142144
    143145        $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
    144 
    145         $ids = array();
    146146        foreach ( $users as $user ) {
    147147            update_user_caches( $user );
    148             $ids[] = $user->ID;
    149         }
    150         update_meta_cache( 'user', $ids );
     148        }
    151149    }
    152150endif;
Note: See TracChangeset for help on using the changeset viewer.