REST API: Cache schema in block pattern and menu item endpoints.
Performance improvement to add schema caching to pattern and menu item REST endpoints, so identical schema object are not needlessly regenerated. Props spacedmonkey. Fixes #58657. See [45811]. Built from https://develop.svn.wordpress.org/trunk@56093 git-svn-id: http://core.svn.wordpress.org/trunk@55605 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
88a4cf17a6
commit
d72667d737
|
@ -125,6 +125,10 @@ class WP_REST_Block_Pattern_Categories_Controller extends WP_REST_Controller {
|
|||
* @return array Item schema data.
|
||||
*/
|
||||
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' => 'block-pattern-category',
|
||||
|
@ -151,6 +155,8 @@ class WP_REST_Block_Pattern_Categories_Controller extends WP_REST_Controller {
|
|||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
$this->schema = $schema;
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,6 +199,10 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {
|
|||
* @return array Item schema data.
|
||||
*/
|
||||
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' => 'block-pattern',
|
||||
|
@ -287,6 +291,8 @@ class WP_REST_Block_Patterns_Controller extends WP_REST_Controller {
|
|||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
$this->schema = $schema;
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,6 +67,10 @@ class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller {
|
|||
* @return array Item schema data.
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
if ( $this->schema ) {
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
|
||||
// Do not cache this schema because all properties are derived from parent controller.
|
||||
$schema = parent::get_item_schema();
|
||||
|
||||
|
@ -86,7 +90,9 @@ class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller {
|
|||
unset( $schema['properties']['title']['properties']['rendered'] );
|
||||
unset( $schema['properties']['content']['properties']['rendered'] );
|
||||
|
||||
return $schema;
|
||||
$this->schema = $schema;
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -710,6 +710,10 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
|
|||
* @return array Item schema data.
|
||||
*/
|
||||
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' => $this->post_type,
|
||||
|
@ -914,7 +918,9 @@ class WP_REST_Menu_Items_Controller extends WP_REST_Posts_Controller {
|
|||
$schema['links'] = $schema_links;
|
||||
}
|
||||
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
$this->schema = $schema;
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -523,6 +523,10 @@ class WP_REST_Menus_Controller extends WP_REST_Terms_Controller {
|
|||
* @return array Item schema data.
|
||||
*/
|
||||
public function get_item_schema() {
|
||||
if ( $this->schema ) {
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
|
||||
$schema = parent::get_item_schema();
|
||||
unset( $schema['properties']['count'], $schema['properties']['link'], $schema['properties']['taxonomy'] );
|
||||
|
||||
|
@ -566,6 +570,8 @@ class WP_REST_Menus_Controller extends WP_REST_Terms_Controller {
|
|||
'type' => 'boolean',
|
||||
);
|
||||
|
||||
return $schema;
|
||||
$this->schema = $schema;
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.3-alpha-56092';
|
||||
$wp_version = '6.3-alpha-56093';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue