Make WordPress Core

Changeset 56093


Ignore:
Timestamp:
06/28/2023 03:51:23 PM (16 months ago)
Author:
kadamwhite
Message:

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].

Location:
trunk/src/wp-includes/rest-api/endpoints
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php

    r55692 r56093  
    126126     */
    127127    public function get_item_schema() {
     128        if ( $this->schema ) {
     129            return $this->add_additional_fields_schema( $this->schema );
     130        }
     131
    128132        $schema = array(
    129133            '$schema'    => 'http://json-schema.org/draft-04/schema#',
     
    152156        );
    153157
    154         return $this->add_additional_fields_schema( $schema );
     158        $this->schema = $schema;
     159
     160        return $this->add_additional_fields_schema( $this->schema );
    155161    }
    156162}
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php

    r56063 r56093  
    200200     */
    201201    public function get_item_schema() {
     202        if ( $this->schema ) {
     203            return $this->add_additional_fields_schema( $this->schema );
     204        }
     205
    202206        $schema = array(
    203207            '$schema'    => 'http://json-schema.org/draft-04/schema#',
     
    288292        );
    289293
    290         return $this->add_additional_fields_schema( $schema );
     294        $this->schema = $schema;
     295
     296        return $this->add_additional_fields_schema( $this->schema );
    291297    }
    292298}
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php

    r52582 r56093  
    6868     */
    6969    public function get_item_schema() {
     70        if ( $this->schema ) {
     71            return $this->add_additional_fields_schema( $this->schema );
     72        }
     73
    7074        // Do not cache this schema because all properties are derived from parent controller.
    7175        $schema = parent::get_item_schema();
     
    8791        unset( $schema['properties']['content']['properties']['rendered'] );
    8892
    89         return $schema;
     93        $this->schema = $schema;
     94
     95        return $this->add_additional_fields_schema( $this->schema );
    9096    }
    9197
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php

    r55822 r56093  
    711711     */
    712712    public function get_item_schema() {
     713        if ( $this->schema ) {
     714            return $this->add_additional_fields_schema( $this->schema );
     715        }
     716
    713717        $schema = array(
    714718            '$schema' => 'http://json-schema.org/draft-04/schema#',
     
    915919        }
    916920
    917         return $this->add_additional_fields_schema( $schema );
     921        $this->schema = $schema;
     922
     923        return $this->add_additional_fields_schema( $this->schema );
    918924    }
    919925
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php

    r55822 r56093  
    524524     */
    525525    public function get_item_schema() {
     526        if ( $this->schema ) {
     527            return $this->add_additional_fields_schema( $this->schema );
     528        }
     529
    526530        $schema = parent::get_item_schema();
    527531        unset( $schema['properties']['count'], $schema['properties']['link'], $schema['properties']['taxonomy'] );
     
    567571        );
    568572
    569         return $schema;
     573        $this->schema = $schema;
     574
     575        return $this->add_additional_fields_schema( $this->schema );
    570576    }
    571577}
Note: See TracChangeset for help on using the changeset viewer.