[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:50:09 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 SergeyBiryukov):

 Replying to [comment:7 pbiron]:
 > 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.

 Thanks for bringing this up! That was my initial thought as well, but
 after a closer look it turned out  that a `return true` inside a
 `foreach()` loop is actually more common in the existing code:

 * [source:tags/5.3.2/src/wp-includes/rest-api/endpoints/class-wp-rest-
 post-statuses-controller.php?marks=89#L75
 WP_REST_Post_Statuses_Controller::get_items_permissions_check()]
 * [source:tags/5.3.2/src/wp-includes/rest-api/endpoints/class-wp-rest-
 post-statuses-controller.php?marks=167#L149
 WP_REST_Post_Statuses_Controller::check_read_permission()]
 * [source:tags/5.3.2/src/wp-includes/rest-api/endpoints/class-wp-rest-
 post-types-controller.php?marks=86#L74
 WP_REST_Post_Types_Controller::get_items_permissions_check()]
 * [source:tags/5.3.2/src/wp-includes/rest-api/endpoints/class-wp-rest-
 posts-controller.php?marks=1307#L1283
 WP_REST_Posts_Controller::check_assign_terms_permission()]
 * [source:tags/5.3.2/src/wp-includes/rest-api/endpoints/class-wp-rest-
 taxonomies-controller.php?marks=92#L75
 WP_REST_Taxonomies_Controller::get_items_permissions_check()]

 I went back and forth for a bit, as I also find a single "success" return
 at the end more readable, but ultimately chose to be consistent with most
 of the existing checks, since refactoring them seemed out of scope for
 this ticket.

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


More information about the wp-trac mailing list