[wp-trac] [WordPress Trac] #58657: Add in missing caching to `get_item_schema` method to new endpoint

WordPress Trac noreply at wordpress.org
Thu Aug 24 18:22:59 UTC 2023


#58657: Add in missing caching to `get_item_schema` method to new endpoint
--------------------------+---------------------------
 Reporter:  spacedmonkey  |       Owner:  spacedmonkey
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  6.3.2
Component:  REST API      |     Version:  5.0
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  performance
--------------------------+---------------------------

Comment (by kadamwhite):

 The background for that comment is here:
 https://core.trac.wordpress.org/ticket/47871#comment:5 Specifically,

 > I opted to cache only the value of the schema computed within the
 get_item_schema method, and not the final output of
 $this->add_additional_fields_schema(). In theory we could probably cache
 that final value safely in most cases, as an individual REST response
 lifecycle is fairly self-contained and linear; but in practice the order
 of operations we test for in **our unit test suite currently validates
 that we can append rest fields to an endpoint between endpoint
 instantiation and the delivery of the final request**, and it seemed
 unsafe to break that assumption.

 Emphasis added to highlight that this patch passed all unit test suites
 without any test modifications, so that assumption was either inaccurate
 or else some other change in the past few years changed things already.
 Moreover, the documentation for `register_rest_field` has always
 encouraged doing so on `rest_api_init`. Modifying fields on the fly while
 fulfilling a request to me is an anti-pattern that we have never
 documented or encouraged, and do not need to support.

 @TimothyBlynJacobs My instinct is to remove the comment and leave the
 caching in place as-is, but I would like a second opinion.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58657#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list