Opened 3 years ago
Last modified 9 days ago
#57416 assigned enhancement
Do not split query if requesting one post
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 3.0 |
| Component: | Query | Keywords: | good-first-bug has-patch dev-feedback has-unit-tests needs-refresh |
| Focuses: | performance | Cc: |
Description
When using WP_Query and requesting posts_per_page = 1, there is little to no value in splitting the query and priming posts using _prime_post_caches. This results in one query to get the posts and another to prime it. This means two database queries when this could simply be one.
Attachments (2)
Change History (11)
#2
@
3 years ago
- Keywords has-patch dev-feedback needs-testing added; needs-patch removed
The patch simply checks query field 'posts_per_page' equals to 1 and sets split flag to false in this case and skips other filtering whether to split.
@
2 years ago
Add a condition to split_the_query for whether the call is for a single post and add unit tests.
#5
@
2 years ago
I refreshed the patch, but also changed the implementation a little from the original, in that it doesn't skip over the filter. Also added unit tests.
This ticket was mentioned in PR #7025 on WordPress/wordpress-develop by locol-media-dev.
19 months ago
#7
- Keywords has-unit-tests added; needs-unit-tests removed
This ticket was mentioned in Slack in #core-performance by adamsilverstein. View the logs.
13 months ago
#9
@
9 days ago
- Keywords needs-refresh added; needs-testing removed
I attempted to apply the PR patch from https://github.com/WordPress/wordpress-develop/pull/7025 against current trunk (7.0-alpha), but it does not apply cleanly.
The patch fails in src/wp-includes/class-wp-query.php (.rej file generated), so testing isn’t currently possible.
Marking this as needs-refresh. Removing needs-testing until a refreshed patch/PR is provided.
Patch checks for post per page == 1 before splitting the query