WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/15/2019 09:08:05 PM (2 months ago)
Author:
kadamwhite
Message:

REST API: Cache results of get_item_schema on controller instances for performance.

Caches the output of get_item_schema() to avoid redundant recomputation of translatable strings and other computed values. This method is called many times per item in each REST request, and the results of the method should not vary between calls.
Additional schema fields are not cached.

Props kadamwhite, joehoyle, TimothyBlynJacobs.
Fixes #47871.

File:
1 edited

Legend:

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

    r45424 r45811  
    25232523    public function test_get_item_schema_show_avatar() {
    25242524        update_option( 'show_avatars', false );
     2525
     2526        // Re-initialize the controller to cache-bust schemas from prior test runs.
     2527        $GLOBALS['wp_rest_server']->override_by_default = true;
     2528        $controller                                     = new WP_REST_Users_Controller();
     2529        $controller->register_routes();
     2530        $GLOBALS['wp_rest_server']->override_by_default = false;
     2531
    25252532        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' );
    25262533        $response   = rest_get_server()->dispatch( $request );
Note: See TracChangeset for help on using the changeset viewer.