Make WordPress Core


Ignore:
Timestamp:
09/23/2019 08:24:59 PM (5 years 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-comments-controller.php

    r45932 r46272  
    15931593     */
    15941594    protected function check_read_post_permission( $post, $request ) {
    1595         $posts_controller = new WP_REST_Posts_Controller( $post->post_type );
    15961595        $post_type        = get_post_type_object( $post->post_type );
     1596        $posts_controller = $post_type->get_rest_controller();
     1597
     1598        // Ensure the posts controller is specifically a WP_REST_Posts_Controller instance
     1599        // before using methods specific to that controller.
     1600        if ( ! $posts_controller instanceof WP_REST_Posts_Controller ) {
     1601            $posts_controller = new WP_REST_Posts_Controller( $post->post_type );
     1602        }
    15971603
    15981604        $has_password_filter = false;
Note: See TracChangeset for help on using the changeset viewer.