WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/23/2019 08:24:59 PM (8 weeks ago)
Author:
kadamwhite
Message:

REST API: Introduce WP_Post_Type::get_rest_controller() caching method to prevent unnecessary REST controller construction.

Cache REST controller references on their associated post type object to prevent unnecessary controller re-instantiation, which previously caused "rest_prepare_{$post_type}" and "rest_{$post_type}_query" to run twice per request.

Props TimothyBlynJacobs, patrelentlesstechnologycom.
Fixes #45677.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

    r46069 r46272  
    5050    public function __construct( $parent_post_type ) {
    5151        $this->parent_post_type  = $parent_post_type;
    52         $this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
    5352        $this->namespace         = 'wp/v2';
    5453        $this->rest_base         = 'revisions';
    5554        $post_type_object        = get_post_type_object( $parent_post_type );
    5655        $this->parent_base       = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
     56        $this->parent_controller = $post_type_object->get_rest_controller();
     57
     58        if ( ! $this->parent_controller ) {
     59            $this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
     60        }
    5761    }
    5862
Note: See TracChangeset for help on using the changeset viewer.