Changeset 59235
- Timestamp:
- 10/14/2024 10:20:09 PM (7 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-thumbnail-template.php
r55821 r59235 113 113 $thumb_ids = array(); 114 114 115 /* 116 * $wp_query may contain an array of post objects or post IDs. 117 * 118 * This ensures the cache is primed for all post objects to avoid 119 * `get_post()` calls in `get_the_post_thumbnail()` triggering an 120 * additional database call for each post. 121 */ 122 $parent_post_ids = array(); 115 123 foreach ( $wp_query->posts as $post ) { 116 $id = get_post_thumbnail_id( $post->ID ); 124 if ( $post instanceof WP_Post ) { 125 $parent_post_ids[] = $post->ID; 126 } elseif ( is_int( $post ) ) { 127 $parent_post_ids[] = $post; 128 } 129 } 130 _prime_post_caches( $parent_post_ids, false, true ); 131 132 foreach ( $wp_query->posts as $post ) { 133 $id = get_post_thumbnail_id( $post ); 117 134 if ( $id ) { 118 135 $thumb_ids[] = $id; -
trunk/tests/phpunit/tests/post/thumbnails.php
r57105 r59235 69 69 } 70 70 71 public function test_update_post_thumbnail_cache() { 72 set_post_thumbnail( self::$post, self::$attachment_id ); 73 71 /** 72 * Ensure `update_post_thumbnail_cache()` works when querying post objects. 73 * 74 * @ticket 59521 75 * @ticket 30017 76 * @ticket 33968 77 * 78 * @covers ::update_post_thumbnail_cache 79 */ 80 public function test_update_post_thumbnail_cache_when_querying_full_post_objects() { 81 set_post_thumbnail( self::$post, self::$attachment_id ); 82 83 // Test case where `$query->posts` should return Array of post objects. 74 84 $query = new WP_Query( 75 85 array( … … 80 90 ); 81 91 82 $this->assertFalse( $query->thumbnails_cached );92 $this->assertFalse( $query->thumbnails_cached, 'Thumbnails should not be cached prior to calling update_post_thumbnail_cache().' ); 83 93 84 94 update_post_thumbnail_cache( $query ); 85 95 86 $this->assertTrue( $query->thumbnails_cached ); 96 $this->assertTrue( $query->thumbnails_cached, 'Thumbnails should be cached after calling update_post_thumbnail_cache().' ); 97 } 98 99 /** 100 * Ensure `update_post_thumbnail_cache()` works when querying post IDs. 101 * 102 * @ticket 59521 103 * 104 * @covers ::update_post_thumbnail_cache 105 */ 106 public function test_update_post_thumbnail_cache_when_querying_post_id_field() { 107 set_post_thumbnail( self::$post, self::$attachment_id ); 108 109 // Test case where `$query2->posts` should return Array of post IDs. 110 $query = new WP_Query( 111 array( 112 'post_type' => 'any', 113 'post__in' => array( self::$post->ID ), 114 'orderby' => 'post__in', 115 'fields' => 'ids', 116 ) 117 ); 118 119 $this->assertFalse( $query->thumbnails_cached, 'Thumbnails should not be cached prior to calling update_post_thumbnail_cache().' ); 120 121 update_post_thumbnail_cache( $query ); 122 123 $this->assertTrue( $query->thumbnails_cached, 'Thumbnails should be cached after calling update_post_thumbnail_cache().' ); 87 124 } 88 125 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r59120 r59235 1713 1713 rest_get_server()->dispatch( $request ); 1714 1714 1715 $args = $filter->get_args(); 1716 $last = end( $args ); 1717 $this->assertIsArray( $last, 'The last value is not an array' ); 1718 $this->assertSameSets( $parent_ids, $last[1] ); 1715 $events = $filter->get_events(); 1716 $args = wp_list_pluck( $events, 'args' ); 1717 $primed = false; 1718 sort( $parent_ids ); 1719 foreach ( $args as $arg ) { 1720 sort( $arg[1] ); 1721 if ( $parent_ids === $arg[1] ) { 1722 $primed = $arg; 1723 break; 1724 } 1725 } 1726 1727 $this->assertIsArray( $primed, 'The last value is not an array' ); 1728 $this->assertSameSets( $parent_ids, $primed[1] ); 1719 1729 } 1720 1730
Note: See TracChangeset
for help on using the changeset viewer.