Make WordPress Core

Changeset 53483


Ignore:
Timestamp:
06/10/2022 03:15:07 PM (22 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
1 added
5 edited

Legend:

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

    r53482 r53483  
    34353435    public function the_post() {
    34363436        global $post;
     3437
    34373438        if ( ! $this->in_the_loop ) {
    34383439            update_post_author_caches( $this->posts );
    34393440        }
     3441
    34403442        $this->in_the_loop = true;
    34413443
  • trunk/src/wp-includes/pluggable.php

    r53482 r53483  
    144144
    145145        $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
     146
    146147        foreach ( $users as $user ) {
    147148            update_user_caches( $user );
  • trunk/src/wp-includes/post.php

    r53482 r53483  
    74257425
    74267426/**
    7427  * Calls major cache updating functions for list of Post objects.
     7427 * Updates post, term, and metadata caches for a list of post objects.
    74287428 *
    74297429 * @since 1.5.0
    74307430 *
    7431  * @param WP_Post[] $posts             Array of Post objects
     7431 * @param WP_Post[] $posts             Array of post objects (passed by reference).
    74327432 * @param string    $post_type         Optional. Post type. Default 'post'.
    74337433 * @param bool      $update_term_cache Optional. Whether to update the term cache. Default true.
     
    74767476
    74777477/**
    7478  * Prime post author user caches.
     7478 * Updates post author user caches for a list of post objects.
    74797479 *
    74807480 * @since 6.1.0
    74817481 *
    7482  * @param WP_Post[] $posts Array of Post objects
     7482 * @param WP_Post[] $posts Array of post objects.
    74837483 */
    74847484function update_post_author_caches( $posts ) {
     
    74867486    $author_ids = array_map( 'absint', $author_ids );
    74877487    $author_ids = array_unique( array_filter( $author_ids ) );
     7488
    74887489    cache_users( $author_ids );
    74897490}
    74907491
    74917492/**
    7492  * Updates metadata cache for list of post IDs.
     7493 * Updates metadata cache for a list of post IDs.
    74937494 *
    74947495 * Performs SQL query to retrieve the metadata for the post IDs and updates the
  • trunk/tests/phpunit/tests/post/updatePostCache.php

    r53042 r53483  
    11<?php
    22/**
    3  * Test `wp_update_cache()`.
     3 * Test `update_post_cache()`.
    44 *
    55 * @package WordPress
     
    77
    88/**
    9  * Test class for `wp_update_cache()`.
     9 * Test class for `update_post_cache()`.
    1010 *
    1111 * @group post
     
    1919     * Post IDs from the shared fixture.
    2020     *
    21      * @var array
     21     * @var int[]
    2222     */
    2323    public static $post_ids;
  • trunk/tests/phpunit/tests/query.php

    r53482 r53483  
    622622
    623623    /**
    624      * @ticket 55716
    625      */
    626     public function test_prime_user_cache() {
    627         $action = new MockAction();
    628         add_filter( 'update_user_metadata_cache', array( $action, 'filter' ), 10, 2 );
    629         $user_ids = array();
    630         $count    = 5;
    631         for ( $i = 0; $i < $count; $i ++ ) {
    632             $user_ids[ $i ] = self::factory()->user->create();
    633             self::factory()->post->create(
    634                 array(
    635                     'post_type'   => 'post',
    636                     'post_author' => $user_ids[ $i ],
    637                 )
    638             );
    639         }
    640 
    641         $q = new WP_Query(
    642             array(
    643                 'post_type'      => 'post',
    644                 'posts_per_page' => $count,
    645             )
    646         );
    647         while ( $q->have_posts() ) {
    648             $q->the_post();
    649         }
    650 
    651         $args      = $action->get_args();
    652         $last_args = end( $args );
    653         $this->assertSameSets( $user_ids, $last_args[1], 'Ensure that user ids are primed' );
    654     }
    655 
    656     /**
    657624     * @ticket 35601
    658625     */
Note: See TracChangeset for help on using the changeset viewer.