Changeset 53485
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/search/class-wp-rest-post-search-handler.php
r49955 r53485 59 59 60 60 $query_args = array( 61 'post_type' => $post_types, 62 'post_status' => 'publish', 63 'paged' => (int) $request['page'], 64 'posts_per_page' => (int) $request['per_page'], 65 'ignore_sticky_posts' => true, 66 'fields' => 'ids', 61 'post_type' => $post_types, 62 'post_status' => 'publish', 63 'paged' => (int) $request['page'], 64 'posts_per_page' => (int) $request['per_page'], 65 'ignore_sticky_posts' => true, 67 66 ); 68 67 … … 84 83 85 84 $query = new WP_Query(); 86 $found_ids = $query->query( $query_args ); 85 $posts = $query->query( $query_args ); 86 // Querying the whole post object will warm the object cache, avoiding an extra query per result. 87 $found_ids = wp_list_pluck( $posts, 'ID' ); 87 88 $total = $query->found_posts; 88 89 -
trunk/tests/phpunit/tests/rest-api/rest-search-controller.php
r51367 r53485 334 334 335 335 /** 336 * @ticket 55674 337 */ 338 public function test_get_items_search_prime_ids() { 339 $action = new MockAction(); 340 add_filter( 'query', array( $action, 'filter' ), 10, 2 ); 341 342 $query_args = array( 343 'per_page' => 100, 344 'search' => 'foocontent', 345 ); 346 $response = $this->do_request_with_params( $query_args ); 347 $this->assertSame( 200, $response->get_status(), 'Request Status Response is not 200.' ); 348 349 $ids = wp_list_pluck( $response->get_data(), 'id' ); 350 $this->assertSameSets( self::$my_content_post_ids, $ids, 'Query result posts ids do not match with expected ones.' ); 351 352 $args = $action->get_args(); 353 $primed_query_found = false; 354 foreach ( $args as $arg ) { 355 // Primed query will use WHERE ID IN clause. 356 if ( str_contains( $arg[0], 'WHERE ID IN (' . implode( ',', $ids ) ) ) { 357 $primed_query_found = true; 358 break; 359 } 360 } 361 362 $this->assertTrue( $primed_query_found, 'Prime query was not executed.' ); 363 } 364 365 /** 336 366 * Test retrieving a single item isn't possible. 337 367 */
Note: See TracChangeset
for help on using the changeset viewer.