Make WordPress Core


Ignore:
Timestamp:
08/15/2019 09:08:05 PM (6 years 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/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r45632 r45811  
    12161216     */
    12171217    public function get_item_schema() {
     1218        if ( $this->schema ) {
     1219            return $this->add_additional_fields_schema( $this->schema );
     1220        }
     1221
    12181222        $schema = array(
    12191223            '$schema'    => 'http://json-schema.org/draft-04/schema#',
     
    13651369        $schema['properties']['meta'] = $this->meta->get_field_schema();
    13661370
    1367         return $this->add_additional_fields_schema( $schema );
     1371        $this->schema = $schema;
     1372        return $this->add_additional_fields_schema( $this->schema );
    13681373    }
    13691374
Note: See TracChangeset for help on using the changeset viewer.