[wp-trac] [WordPress Trac] #57221: Opportunity for optimization on invalid query to REST API Search Controller

WordPress Trac noreply at wordpress.org
Mon Nov 28 21:17:25 UTC 2022


#57221: Opportunity for optimization on invalid query to REST API Search Controller
-------------------------+-----------------------------
 Reporter:  Starbuck     |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  REST API     |    Version:  trunk
 Severity:  minor        |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Ref: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/rest-
 api/endpoints/class-wp-rest-search-controller.php#L119

 Here we see get_items executes a query and gets a list of $ids. Then it
 loops through all $ids to prepare the response. And **then** it checks the
 total number of records to see if the requested page is larger than the
 number of pages available.

 This is a proposal to check $max_pages before the response preparation, to
 avoid the loop if the request is pre-destined to return an error anyway.

 This would only provide a performance benefit on invalid queries. But
 looking up at line 115, function get_items_permission_check always returns
 true. I can imagine a DOS where a large number of search queries are
 queued up just to keep a system busy.

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


More information about the wp-trac mailing list