Query: Increase WP_Query
cache hits for equivalent arguments.
Introduces normalization a number of arguments passed to WP_Query
to increase cache hits for equivalent requests. For example author__in => [ 1, 2 ]
and author__in => [ 2, 1 ]
will now hit the same cache.
Prior to generating the SQL request and cache key, the following are sorted, made unique and type cast as appropriate.
post_type
when passed as an array
post_status
when passed as an array
term_query
s containing terms
cat
category__in
category__not_in
category__and
tag_slug__in
tag__in
tag__not_in
tag__and
tag_slug__in
tag_slug__and
post_parent__not_in
author
author__not_in
author__in
The following are sorted for the purposes of generating the cache key and SQL WHERE
clause but unmodified for use in the ORDER BY
SQL clause:
post_name__in
post__in
post_parent__in
This commit includes changes to unrelated tests, assertions in Tests_Query_ParseQuery::test_parse_query_cat_array_mixed()
and WP_Test_REST_Posts_Controller::test_get_items_not_sticky_with_exclude()
have been modified to account for the sorting of the items above.
Props thekt12, peterwilsoncc, spacedmonkey, joemcgill, flixos90, mukesh27, pbearne, swissspidy.
Fixes #59516.