-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WP_Query: sort more arrays to improve cache hits. #7497
base: trunk
Are you sure you want to change the base?
WP_Query: sort more arrays to improve cache hits. #7497
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
@peterwilsoncc I was concerned that sorting might effect the order of the output too, looks like it doesn't. Can we also ensure, https://core.trac.wordpress.org/ticket/59492#comment:3 is handled (if not), please. If there is only one element in the array it should be converted into string. I remember getting that scenario from a live site, but I can't recall the details. |
The order should only have an effect for items that can be used for the orderby clause, for example
My recollection is that in some instances the use of a string vs an array can result in a different where clause beyond just the use of |
881c8fa
to
c8afd28
Compare
8ab71fb
to
a7243ad
Compare
'term queries order (array)' => array( | ||
'query_vars_1' => array( 'cat' => array( '1', '2' ) ), | ||
'query_vars_2' => array( 'cat' => array( '2', '1' ) ), | ||
), | ||
'term queries order (string)' => array( | ||
'query_vars_1' => array( 'cat' => '1,2' ), | ||
'query_vars_2' => array( 'cat' => '2,1' ), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two are failing. cat
is normalised in the generated SQL query but not in the arguments passed to ::generate_cache_key()
.
I can't figure out why as the query vars are passed to ::parse_term_query()
by reference so sorting it there should work. @joemcgill Can you see what I am missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two are failing.
cat
is normalised in the generated SQL query but not in the arguments passed to::generate_cache_key()
.I can't figure out why as the query vars are passed to
::parse_term_query()
by reference so sorting it there should work. @joemcgill Can you see what I am missing?
nvm, the tests were testing the wrong thing so I've started testing the cache key generated by WP_Query in bc24627
This reverts commit 23253e8.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Lighter touch alternative to #5347
What
Improves the cache hits for
WP_Query
How
It sorts query variable whenever possible. This results in the SQL queries being normalised so that it doesn't produce different SQL for the same effective arguments. For example
category__in => [1,2]
andcategory__in => [2,1]
produce the sameIN()
clause.Why
Currently the SQL queries and the generated cache key differ for the same effective arguments.
Trac ticket: https://core.trac.wordpress.org/ticket/59516
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.