[wp-trac] [WordPress Trac] #59516: Improve cache key generation in the WP_Query class

WordPress Trac noreply at wordpress.org
Thu Feb 6 05:02:33 UTC 2025


#59516: Improve cache key generation in the WP_Query class
-----------------------------------------------+--------------------------
 Reporter:  spacedmonkey                       |       Owner:  pbearne
     Type:  defect (bug)                       |      Status:  closed
 Priority:  normal                             |   Milestone:  6.8
Component:  Query                              |     Version:
 Severity:  normal                             |  Resolution:  fixed
 Keywords:  has-patch changes-requested early  |     Focuses:  performance
-----------------------------------------------+--------------------------
Changes (by peterwilsoncc):

 * status:  accepted => closed
 * resolution:   => fixed


Comment:

 In [changeset:"59766" 59766]:
 {{{
 #!CommitTicketReference repository="" revision="59766"
 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.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59516#comment:41>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list