Make WordPress Core


Ignore:
Timestamp:
08/15/2019 09:08:05 PM (5 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-block-renderer-controller.php

    r44269 r45811  
    162162     */
    163163    public function get_item_schema() {
    164         return array(
     164        if ( $this->schema ) {
     165            return $this->schema;
     166        }
     167
     168        $this->schema = array(
    165169            '$schema'    => 'http://json-schema.org/schema#',
    166170            'title'      => 'rendered-block',
     
    175179            ),
    176180        );
     181        return $this->schema;
    177182    }
    178183}
Note: See TracChangeset for help on using the changeset viewer.