[wp-trac] [WordPress Trac] #62801: Improve performance of X-WP-TotalPages queries

WordPress Trac noreply at wordpress.org
Sun Jan 12 16:55:06 UTC 2025


#62801: Improve performance of X-WP-TotalPages queries
--------------------------+----------------------------
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  REST API      |    Version:  3.7
 Severity:  normal        |   Keywords:  good-first-bug
  Focuses:  performance   |
--------------------------+----------------------------
 In the REST API, there is a header field called X-WP-TotalPages. This
 field is used to understand how many total pages there are to a REST API
 call.

 This does a call to WP_Query / WP_Comment_Query / WP_User_Query and gets
 the total of number of results for a query. Here are some examples found
 in core.


 - [https://github.com/WordPress/wordpress-
 develop/blob/c0d073d62d32d424d9149619a7fcae48ddb82c26/src/wp-includes
 /rest-api/endpoints/class-wp-rest-posts-controller.php#L463-L470 class-wp-
 rest-posts-controller.php]
 - [https://github.com/WordPress/wordpress-
 develop/blob/c0d073d62d32d424d9149619a7fcae48ddb82c26/src/wp-includes
 /rest-api/endpoints/class-wp-rest-global-styles-revisions-
 controller.php#L195-L202 class-wp-rest-global-styles-revisions-
 controller.php]
 - [https://github.com/WordPress/wordpress-
 develop/blob/c0d073d62d32d424d9149619a7fcae48ddb82c26/src/wp-includes
 /rest-api/endpoints/class-wp-rest-users-controller.php#L367-L372 class-wp-
 rest-users-controller.php]
 - [https://github.com/WordPress/wordpress-
 develop/blob/c0d073d62d32d424d9149619a7fcae48ddb82c26/src/wp-includes
 /rest-api/endpoints/class-wp-rest-comments-controller.php#L294-L304 class-
 wp-rest-comments-controller.php]
 - [https://github.com/WordPress/wordpress-
 develop/blob/c0d073d62d32d424d9149619a7fcae48ddb82c26/src/wp-includes
 /rest-api/endpoints/class-wp-rest-global-styles-revisions-
 controller.php#L195-L202 class-wp-rest-global-styles-revisions-
 controller.php]

 These queries could be improved, by passing different arguments, to the
 query classes.

 For WP_Query requesting only fields 'ids', limiting the query to 1 result,
 and disable priming of term / meta caches.
 For WP_Comment_Query, passing `count` parameter and disable comment meta
 priming.
 For WP_User_Query, questing only fields 'ids', limiting the query to 1
 result and disable priming of user caches.

 This change should be simple, as total counts should be covered by
 existing unit tests.

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


More information about the wp-trac mailing list