Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#56721 closed defect (bug) (fixed)

get_page_by_title: duplicate SQL query

Reported by: davidbinda's profile david.binda Owned by: peterwilsoncc's profile peterwilsoncc
Milestone: 6.1 Priority: normal
Severity: normal Version: 6.1
Component: Posts, Post Types Keywords: has-patch commit
Focuses: performance Cc:

Description

The r54234 has introduced a duplicate SQL query triggered for the get_page_by_title function, as it's executing the SQL query by passing the arguments for a WP_Query directly to the constructor of the class, and then triggering the WP_Query::get_posts() directly, instead of accessing the WP_Query::posts property.

See https://core.trac.wordpress.org/browser/trunk/src/wp-includes/post.php?rev=54320#L5790

Attachments (1)

56721.diff (392 bytes) - added by david.binda 2 years ago.

Download all attachments as: .zip

Change History (12)

@david.binda
2 years ago

#1 @mukesh27
2 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 6.1

Thanks @davidbinda. good cache.

r54234 is merge before some days in 6.1 milestone. Let's move to 6.1 for consideration. feel free to update milestone.

cc. @spacedmonkey @SergeyBiryukov

#2 @spacedmonkey
2 years ago

This patch was meant to be in WordPress 6.1.

#3 @mukesh27
2 years ago

  • Keywords commit added

@spacedmonkey thanks for the confirmation.

56721.diff LGTM.
commit added.

#4 @spacedmonkey
2 years ago

+1 to commit.

This ticket was mentioned in PR #3400 on WordPress/wordpress-develop by peterwilsoncc.


2 years ago
#5

  • Keywords has-unit-tests added

#6 @peterwilsoncc
2 years ago

  • Keywords has-unit-tests removed
  • Owner set to peterwilsoncc
  • Status changed from new to assigned

Thanks for the patch @davidbinda.

I've added a test in the linked pull request and will commit once the checks start passing.

#7 @peterwilsoncc
2 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 54377:

Posts, Post types: Prevent get_page_by_title() parsing query twice.

In get_page_by_title() access the populated WP_Query::posts property directly rather than via the WP_Query::get_posts() method. This removes unnecessary reprocessing of the query.

Follow up to [54234].

Props david.binda, mukesh27, spacedmonkey.
Fixes #56721.

peterwilsoncc commented on PR #3400:


2 years ago
#8

Committed in https://core.trac.wordpress.org/changeset/54377 / 4a9ab59d91f463d7b9021183d0702723fad91c87

#9 @milana_cap
2 years ago

  • Keywords needs-dev-note added

Worth mentioning in performance grouped Dev Note.

#10 @spacedmonkey
2 years ago

@milana_cap This is a bug introduced in 6.1 beta. So no need to mention it. We are already mentioning change to get_page_by_title in the dev note.

#11 @milana_cap
2 years ago

  • Keywords needs-dev-note removed

Thank you @spacedmonkey

Note: See TracTickets for help on using tickets.