Make WordPress Core

Opened 5 months ago

Last modified 3 months ago

#62801 assigned enhancement

Improve performance of X-WP-TotalPages queries

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.9 Priority: normal
Severity: normal Version: 3.7
Component: REST API Keywords: has-patch early commit
Focuses: performance Cc:

Description

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.

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.

Change History (13)

This ticket was mentioned in PR #8113 on WordPress/wordpress-develop by @sukhendu2002.


5 months ago
#1

  • Keywords has-patch added

#2 @johnbillion
5 months ago

Which condition does the $total_posts < 1 logic handle? ie. why is the found_posts property not populated in the main query?

#3 @spacedmonkey
5 months ago

@johnbillion I don't have any context on this one. Maybe @TimothyBlynJacobs @kadamwhite or @rachelbaker would know why this was done.

#4 @joehoyle
5 months ago

Could it be that an out of bounds query means found_posts is 0? I.e. if I hit ?paged=100 when there is only 10 pages, I guess found_posts even with the FOUND_ROWS() returns 0?

This ticket was mentioned in Slack in #core-performance by adamsilverstein. View the logs.


5 months ago

#6 follow-up: @adamsilverstein
5 months ago

  • Keywords reporter-feedback added

Thanks for the PR @Sukhendu2002 - is this ready for review (I see it is draft), or do you have any questions? cc: @spacedmonkey

#7 @kadamwhite
5 months ago

I believe @joehoyle is correct, if you have (say) 12 items and you did page=3, you'd get 0 results back but it's not clear if you've just paged beyond the maximum or if there's no items at all.

#8 @kadamwhite
5 months ago

If it's considered ready for review by @sukhendu2002 I'm +1 on the patch, it appears to achieve @spacedmonkey's desired improvements

#9 in reply to: ↑ 6 @sukhendu2002
5 months ago

Replying to adamsilverstein:

Thanks for the PR @Sukhendu2002 - is this ready for review (I see it is draft), or do you have any questions? cc: @spacedmonkey

Sorry for the delay! I've now marked the PR as ready for review. Let me know if you have any feedback.

@sukhendu2002 commented on PR #8113:


5 months ago
#10

Hey @spacedmonkey, Thanks for the review! I have also applied the change in the WP_REST_Revisions_Controller class. Take a look when you get a chance. Thanks!

#11 @spacedmonkey
4 months ago

  • Milestone changed from Future Release to 6.9
  • Owner set to spacedmonkey
  • Status changed from new to assigned

This looks good. To late to commit in WP 6.8. Adding to WP 6.9 and assigning to me.

This ticket was mentioned in Slack in #core-performance by adamsilverstein. View the logs.


3 months ago

#13 @adamsilverstein
3 months ago

  • Keywords early commit added; good-first-bug reporter-feedback removed
Note: See TracTickets for help on using tickets.