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.


git-svn-id: https://develop.svn.wordpress.org/trunk@45811 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
K. Adam White
2019-08-15 21:08:05 +00:00
parent 94b8a122c4
commit eb468c4446
18 changed files with 106 additions and 14 deletions

View File

@@ -1215,6 +1215,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
* @return array
*/
public function get_item_schema() {
if ( $this->schema ) {
return $this->add_additional_fields_schema( $this->schema );
}
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'comment',
@@ -1364,7 +1368,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
$schema['properties']['meta'] = $this->meta->get_field_schema();
return $this->add_additional_fields_schema( $schema );
$this->schema = $schema;
return $this->add_additional_fields_schema( $this->schema );
}
/**