Make WordPress Core

Opened 2 years ago

Last modified 5 months ago

#57416 assigned enhancement

Do not split query if requesting one post

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Query Keywords: good-first-bug has-patch dev-feedback needs-testing has-unit-tests
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)

57416.diff (2.7 KB) - added by mkox 18 months ago.
Patch checks for post per page == 1 before splitting the query
57416.2.diff (2.1 KB) - added by darthhexx 13 months ago.
Add a condition to split_the_query for whether the call is for a single post and add unit tests.

Download all attachments as: .zip

Change History (9)

#1 @spacedmonkey
22 months ago

  • Owner set to spacedmonkey
  • Status changed from new to assigned

@mkox
18 months ago

Patch checks for post per page == 1 before splitting the query

#2 @mkox
18 months 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.

#3 @soulseekah
17 months ago

  • Keywords needs-unit-tests added

#4 @spacedmonkey
15 months ago

  • Keywords needs-refresh added

This patch needs to be refreshed.

@darthhexx
13 months ago

Add a condition to split_the_query for whether the call is for a single post and add unit tests.

#5 @darthhexx
13 months 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.

#6 @darthhexx
13 months ago

  • Keywords needs-refresh removed

Removed needs-refresh.

This ticket was mentioned in PR #7025 on WordPress/wordpress-develop by locol-media-dev.


5 months ago
#7

  • Keywords has-unit-tests added; needs-unit-tests removed
Note: See TracTickets for help on using tickets.