Query: Some documentation and test improvements for `update_post_author_caches()`:

* Make the descriptions for `update_post_author_caches()` and `update_post_caches()` more specific.
* Move the unit test into its own file, for consistency with `update_post_cache()` tests. This also allows for using shared fixtures in case more tests are added in the future.

Follow-up to [53482].

See #55716.
Built from https://develop.svn.wordpress.org/trunk@53483


git-svn-id: http://core.svn.wordpress.org/trunk@53072 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-06-10 15:17:10 +00:00
parent 2237f67458
commit 9e01bd8adc
4 changed files with 10 additions and 6 deletions

View File

@ -3434,9 +3434,11 @@ class WP_Query {
*/ */
public function the_post() { public function the_post() {
global $post; global $post;
if ( ! $this->in_the_loop ) { if ( ! $this->in_the_loop ) {
update_post_author_caches( $this->posts ); update_post_author_caches( $this->posts );
} }
$this->in_the_loop = true; $this->in_the_loop = true;
if ( -1 == $this->current_post ) { // Loop has just started. if ( -1 == $this->current_post ) { // Loop has just started.

View File

@ -143,6 +143,7 @@ if ( ! function_exists( 'cache_users' ) ) :
$list = implode( ',', $clean ); $list = implode( ',', $clean );
$users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
foreach ( $users as $user ) { foreach ( $users as $user ) {
update_user_caches( $user ); update_user_caches( $user );
} }

View File

@ -7424,11 +7424,11 @@ function clean_post_cache( $post ) {
} }
/** /**
* Calls major cache updating functions for list of Post objects. * Updates post, term, and metadata caches for a list of post objects.
* *
* @since 1.5.0 * @since 1.5.0
* *
* @param WP_Post[] $posts Array of Post objects * @param WP_Post[] $posts Array of post objects (passed by reference).
* @param string $post_type Optional. Post type. Default 'post'. * @param string $post_type Optional. Post type. Default 'post'.
* @param bool $update_term_cache Optional. Whether to update the term cache. Default true. * @param bool $update_term_cache Optional. Whether to update the term cache. Default true.
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true. * @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
@ -7475,21 +7475,22 @@ function update_post_caches( &$posts, $post_type = 'post', $update_term_cache =
} }
/** /**
* Prime post author user caches. * Updates post author user caches for a list of post objects.
* *
* @since 6.1.0 * @since 6.1.0
* *
* @param WP_Post[] $posts Array of Post objects * @param WP_Post[] $posts Array of post objects.
*/ */
function update_post_author_caches( $posts ) { function update_post_author_caches( $posts ) {
$author_ids = wp_list_pluck( $posts, 'post_author' ); $author_ids = wp_list_pluck( $posts, 'post_author' );
$author_ids = array_map( 'absint', $author_ids ); $author_ids = array_map( 'absint', $author_ids );
$author_ids = array_unique( array_filter( $author_ids ) ); $author_ids = array_unique( array_filter( $author_ids ) );
cache_users( $author_ids ); cache_users( $author_ids );
} }
/** /**
* Updates metadata cache for list of post IDs. * Updates metadata cache for a list of post IDs.
* *
* Performs SQL query to retrieve the metadata for the post IDs and updates the * Performs SQL query to retrieve the metadata for the post IDs and updates the
* metadata cache for the posts. Therefore, the functions, which call this * metadata cache for the posts. Therefore, the functions, which call this

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.1-alpha-53482'; $wp_version = '6.1-alpha-53483';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.