Changeset 56656
- Timestamp:
- 09/21/2023 07:32:55 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-query.php
r56549 r56656 3271 3271 } 3272 3272 3273 $is_unfiltered_query = $old_request == $this->request && "{$wpdb->posts}.*" === $fields; 3274 3273 3275 if ( null === $this->posts ) { 3274 3276 $split_the_query = ( 3275 $old_request == $this->request 3276 && "{$wpdb->posts}.*" === $fields 3277 $is_unfiltered_query 3277 3278 && ( 3278 3279 wp_using_ext_object_cache() … … 3337 3338 $this->posts = array_map( 'get_post', $this->posts ); 3338 3339 } 3340 3341 $unfiltered_posts = $this->posts; 3339 3342 3340 3343 if ( $q['cache_results'] && $id_query_is_cacheable && ! $cache_found ) { … … 3530 3533 3531 3534 if ( $q['cache_results'] ) { 3532 update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 3535 if ( $is_unfiltered_query && $unfiltered_posts === $this->posts ) { 3536 update_post_caches( $this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 3537 } else { 3538 $post_ids = wp_list_pluck( $this->posts, 'ID' ); 3539 _prime_post_caches( $post_ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 3540 } 3533 3541 } 3534 3542 -
trunk/tests/phpunit/tests/query/cacheResults.php
r55349 r56656 1081 1081 1082 1082 /** 1083 * @ticket 58599 1084 */ 1085 public function test_query_posts_fields_request() { 1086 global $wpdb; 1087 1088 $args = array( 1089 'update_post_meta_cache' => false, 1090 'update_post_term_cache' => false, 1091 'no_found_rows' => true, 1092 ); 1093 1094 add_filter( 'posts_fields_request', array( $this, 'filter_posts_fields_request' ) ); 1095 1096 $before = get_num_queries(); 1097 $query1 = new WP_Query(); 1098 $posts1 = $query1->query( $args ); 1099 $after = get_num_queries(); 1100 1101 foreach ( $posts1 as $_post ) { 1102 $this->assertNotSame( get_post( $_post->ID )->post_content, $_post->post_content ); 1103 } 1104 1105 $this->assertSame( 2, $after - $before, 'There should only be 2 queries run, one for request and one prime post objects.' ); 1106 1107 $this->assertStringContainsString( 1108 "SELECT $wpdb->posts.*", 1109 $wpdb->last_query, 1110 'Check that _prime_post_caches is called.' 1111 ); 1112 } 1113 1114 public function filter_posts_fields_request( $fields ) { 1115 global $wpdb; 1116 return "{$wpdb->posts}.ID"; 1117 } 1118 1119 /** 1120 * @ticket 58599 1121 * @dataProvider data_query_filter_posts_results 1122 */ 1123 public function test_query_filter_posts_results( $filter ) { 1124 global $wpdb; 1125 1126 $args = array( 1127 'update_post_meta_cache' => false, 1128 'update_post_term_cache' => false, 1129 'no_found_rows' => true, 1130 ); 1131 1132 add_filter( $filter, array( $this, 'filter_posts_results' ) ); 1133 1134 $before = get_num_queries(); 1135 $query1 = new WP_Query(); 1136 $posts1 = $query1->query( $args ); 1137 $after = get_num_queries(); 1138 1139 $this->assertCount( 1, $posts1 ); 1140 1141 $this->assertSame( 2, $after - $before, 'There should only be 2 queries run, one for request and one prime post objects.' ); 1142 1143 $this->assertStringContainsString( 1144 "SELECT $wpdb->posts.*", 1145 $wpdb->last_query, 1146 'Check that _prime_post_caches is called.' 1147 ); 1148 } 1149 1150 public function filter_posts_results() { 1151 return array( get_post( self::$posts[0] ) ); 1152 } 1153 1154 public function data_query_filter_posts_results() { 1155 return array( 1156 array( 'posts_results' ), 1157 array( 'the_posts' ), 1158 ); 1159 } 1160 1161 /** 1083 1162 * @ticket 22176 1084 1163 */
Note: See TracChangeset
for help on using the changeset viewer.