Changeset 53482
- Timestamp:
- 06/10/2022 01:37:52 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r53469 r53482 3435 3435 public function the_post() { 3436 3436 global $post; 3437 if ( ! $this->in_the_loop ) { 3438 update_post_author_caches( $this->posts ); 3439 } 3437 3440 $this->in_the_loop = true; 3438 3441 -
trunk/src/wp-includes/pluggable.php
r53480 r53482 133 133 global $wpdb; 134 134 135 update_meta_cache( 'user', $user_ids ); 136 135 137 $clean = _get_non_cached_ids( $user_ids, 'users' ); 136 138 … … 142 144 143 145 $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); 144 145 $ids = array();146 146 foreach ( $users as $user ) { 147 147 update_user_caches( $user ); 148 $ids[] = $user->ID; 149 } 150 update_meta_cache( 'user', $ids ); 148 } 151 149 } 152 150 endif; -
trunk/src/wp-includes/post.php
r53456 r53482 7476 7476 7477 7477 /** 7478 * Prime post author user caches. 7479 * 7480 * @since 6.1.0 7481 * 7482 * @param WP_Post[] $posts Array of Post objects 7483 */ 7484 function update_post_author_caches( $posts ) { 7485 $author_ids = wp_list_pluck( $posts, 'post_author' ); 7486 $author_ids = array_map( 'absint', $author_ids ); 7487 $author_ids = array_unique( array_filter( $author_ids ) ); 7488 cache_users( $author_ids ); 7489 } 7490 7491 /** 7478 7492 * Updates metadata cache for list of post IDs. 7479 7493 * -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r52363 r53482 369 369 370 370 $posts = array(); 371 372 update_post_author_caches( $query_result ); 371 373 372 374 foreach ( $query_result as $post ) { -
trunk/tests/phpunit/tests/query.php
r53370 r53482 622 622 623 623 /** 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 /** 624 657 * @ticket 35601 625 658 */
Note: See TracChangeset
for help on using the changeset viewer.