[wp-trac] [WordPress Trac] #50700: REST API: Small optimizations to filtering by context

WordPress Trac noreply at wordpress.org
Sun Jul 19 18:00:17 UTC 2020


#50700: REST API: Small optimizations to filtering by context
--------------------------+-----------------------------
 Reporter:  dlh           |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  trunk
 Severity:  normal        |   Keywords:  has-patch
  Focuses:                |
--------------------------+-----------------------------
 As previously
 [https://wordpress.slack.com/archives/C02RQC26G/p1592404768292500
 discussed in Slack], the attached patch proposes some minor optimizations
 to `rest_filter_response_by_context()` and adds a few tests.

 In the patch:

 - Avoid recalculating the schema `type` with each iteration of the loop.

 - If the schema type is an array including both `array` and `object`,
 attempt to use the best type for the given response data (currently, the
 data is always be treated as `array`). Includes a test for this case.

 - If the type is `array` and the context of `items` doesn't match, return
 an empty array and break out of the loop since each item will be checked
 against the same schema anyway. Includes a test for this case.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50700>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list