Make WordPress Core

Opened 18 months ago

Last modified 7 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 needs-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 12 months ago.
Patch checks for post per page == 1 before splitting the query
57416.2.diff (2.1 KB) - added by darthhexx 7 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 (8)

#1 @spacedmonkey
15 months ago

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

@mkox
12 months ago

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

#2 @mkox
12 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
11 months ago

  • Keywords needs-unit-tests added

#4 @spacedmonkey
9 months ago

  • Keywords needs-refresh added

This patch needs to be refreshed.

@darthhexx
7 months ago

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

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

  • Keywords needs-refresh removed

Removed needs-refresh.

Note: See TracTickets for help on using tickets.