Make WordPress Core


Ignore:
Timestamp:
06/10/2022 03:45:45 PM (2 years ago)
Author:
spacedmonkey
Message:

REST API: Improve post cache priming in WP_REST_Post_Search_Handler class.

In the WP_REST_Post_Search_Handler class, ensure that post, post meta and term caches are correctly primed when performing a search.

Props furi3r, spacedmonkey, TimothyBlynJacobs, audrasjb, peterwilsoncc.
Fixes #55674.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-search-controller.php

    r51367 r53485  
    334334
    335335    /**
     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    /**
    336366     * Test retrieving a single item isn't possible.
    337367     */
Note: See TracChangeset for help on using the changeset viewer.