Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#55360 closed enhancement (fixed)

Add limit to query in WP_Tax_Query

Reported by: spacedmonkey Owned by: spacedmonkey
Priority: normal Milestone: 6.0
Component: Taxonomy Version: 4.7
Severity: normal Keywords: has-patch has-unit-tests commit has-dev-note
Cc: Focuses: performance

Description

The call to get_terms in WP_Tax_Query, does not currently have a limit set. This because some taxonomies are hierarchical and could have nested terms. But for none hierarchical taxonomies, a limit can and should be set. This limit will improve query performance and will improve likely of hitting an existing term query cache.

Attachments (2)

Screenshot 2022-03-10 at 00.19.50.png​ (1.2 MB ) - added by spacedmonkey 5 years ago.
After patch
Screenshot 2022-03-10 at 00.20.13.png​ (1.2 MB ) - added by spacedmonkey 5 years ago.
Before patch

Change History (10)

This ticket was mentioned in ​PR #2396 on ​WordPress/wordpress-develop by ​spacedmonkey.


5 years ago
#1

  • Keywords has-patch added

#2 @spacedmonkey
5 years ago

  • Keywords has-unit-tests added

I recommend testing this ticket along side #55352.

With this change in place, it means that the early call to get_term_by populates the cache for the taxonomy query. This means one less query per page on tag pages.

Even without this benefit, limiting the query, makes the query return first, as SQL, stop processing once the limit is meet.

#3 @spacedmonkey
5 years ago

  • Milestone Awaiting Review → 6.0

#4 @peterwilsoncc
5 years ago

  • Keywords commit added

Linked ​pull request approved, @spacedmonkey are you able to take the honors for commit?

#5 @spacedmonkey
5 years ago

  • Resolution → fixed
  • Status assigned → closed

In 53037:

Taxonomy: Improve performance by taxonomy queries by adding a limitting requested terms.

Add a limit to the number of terms requested in taxonomy queries. This improves the performance of the query and the likelihood of hitting an existing term query cache.

Props Spacedmonkey, peterwilsoncc, flixos90.
Fixes #55360.

​spacedmonkey commented on ​PR #2396:


5 years ago
#6

Merged into core.

#7 @spacedmonkey
4 years ago

Dev note ready for ​review.

Note: See TracTickets for help on using tickets.