#58657 closed defect (bug) (fixed)
Add in missing caching to `get_item_schema` method to new endpoint
Reported by: | spacedmonkey | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | 5.0 |
Component: | REST API | Keywords: | |
Focuses: | performance | Cc: |
Description
In [45811] the schema was cached in a property of a the class. This was done for performance reasons. However new endpoints I have been added and this caching was not added. Reviewing code, the following endpoints are missing the caching.
WP_REST_Block_Pattern_Categories_Controller
WP_REST_Menus_Controller
WP_REST_Menu_Items_Controller
WP_REST_Blocks_Controller
WP_REST_Block_Pattern_Categories_Controller
Change History (17)
This ticket was mentioned in PR #4735 on WordPress/wordpress-develop by @spacedmonkey.
18 months ago
#1
- Keywords has-patch added; needs-patch removed
#2
@
18 months ago
Gutenberg PR - https://github.com/WordPress/gutenberg/pull/52045
#3
@
18 months ago
- Keywords commit added
- Owner set to kadamwhite
- Status changed from new to accepted
#4
@
18 months ago
- Owner changed from kadamwhite to spacedmonkey
- Status changed from accepted to assigned
#6
follow-up:
↓ 7
@
16 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reviewing the r56093 , it's adding a caching to the WP_REST_Blocks_Controller::get_item_schema
right above a comment which says: // Do not cache this schema because all properties are derived from parent controller.
( see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php?rev=56093#L75 )
I haven't been able to figure out whether the caching was omitted here as redundant or whether there are any functional limits to the caching.
IMHO, either the comment should be removed as misleading, or the caching should not have be added there. There might a similar case in WP_REST_Menus_Controller::get_item_schema
which is also deriving the properties from parent controller ( see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php?rev=56093#L530 )
#7
in reply to:
↑ 6
@
16 months ago
Replying to david.binda:
Reviewing the r56093 , it's adding a caching to the
WP_REST_Blocks_Controller::get_item_schema
right above a comment which says:// Do not cache this schema because all properties are derived from parent controller.
( see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php?rev=56093#L75 )
Thanks for bringing this up!
I'm also not entirely clear on the consequences, so pinging folks with props + comments on that particular line for feedback.
cc: @spacedmonkey @kadamwhite @joehoyle @TimothyBlynJacobs @johnjamesjacoby
Edit to add:
See #47871
#8
@
16 months ago
- Keywords has-patch commit removed
- Milestone changed from 6.3 to 6.3.1
As we're very close to 6.3 final release, let's move this ticket to milestone 6.3.1.
By the way, it would probably be better to open a follow-up ticket to address this issue so we can keep this one fixed in milestone 6.3.
#10
@
16 months ago
- Milestone changed from 6.3.1 to 6.3.2
Moving to milestone 6.3.2 as WP 6.3.1 is going to be released in the next few days.
#11
@
16 months ago
My memory is that we felt at the time like the caching was unnecessary because it would already be in place at a higher level, but I don't personally see any downside to having added it -- it feels like a micro-optimization with uncertain payoff, which is not worth having one or two controllers work different from all the others. @johnjamesjacoby called me out on the comment at the time and I now agree that the uncertainty it introduces is not good.
@TimothyBlynJacobs My instinct is to remove the comment and leave the caching in place as-is, but I would like a second opinion.
This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.
16 months ago
kadamwhite commented on PR #4735:
16 months ago
#13
Committed in https://core.trac.wordpress.org/changeset/56093
Trac ticket: https://core.trac.wordpress.org/ticket/58657#ticket