[wp-trac] [WordPress Trac] #49118: REST API: minor performance improvement for /wp/v2/users?who=authors

WordPress Trac noreply at wordpress.org
Fri Jan 3 03:26:29 UTC 2020


#49118: REST API: minor performance improvement for /wp/v2/users?who=authors
------------------------------+-----------------------------
 Reporter:  pbiron            |       Owner:  SergeyBiryukov
     Type:  enhancement       |      Status:  closed
 Priority:  normal            |   Milestone:  5.4
Component:  Users             |     Version:  4.9.6
 Severity:  normal            |  Resolution:  fixed
 Keywords:  has-patch commit  |     Focuses:  rest-api
------------------------------+-----------------------------

Comment (by pbiron):

 @SergeyBiryukov One comment about the change you made to immediately
 return instead of just breading out the loop: that might make it harder to
 add other checks to
 `WP_REST_Users_Controller::get_items_permissions_check()` in the future.

 The basic pattern of all those checks seems to be: early return (with a
 `WP_Error`) when the permission check fails and do a single "success"
 return at the end.

 The change you made kind of breaks that pattern...and ''might'' make it
 harder for a contributor submitting a future patch that adds a new check:
 they'd have to realize that any new checks need to go **before** the
 `'authors' === $request['who'` check.

 Of course, that's something that a committer would need to check before
 committing such future patches, but I'm thinking it would be better to
 make it easier for contributors to not have to worry about noticing the
 early "success" return.

 Just a thought.

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


More information about the wp-trac mailing list