[wp-trac] [WordPress Trac] #59442: Duplicate query in WP_Query

WordPress Trac noreply at wordpress.org
Wed May 8 22:50:04 UTC 2024


#59442: Duplicate query in WP_Query
-------------------------------------------------+-------------------------
 Reporter:  spacedmonkey                         |       Owner:
                                                 |  spacedmonkey
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  6.6
Component:  Query                                |     Version:  6.2
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch early has-unit-tests       |     Focuses:
  commit                                         |  performance
-------------------------------------------------+-------------------------
Changes (by spacedmonkey):

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


Comment:

 In [changeset:"58122" 58122]:
 {{{
 #!CommitTicketReference repository="" revision="58122"
 Query: Improve cache key generation.

 Query caching in `WP_Query` was added in [53941]. When this functionality
 was added to the `WP_Query` class, a number of edge cases were missed that
 would result in redundant duplicate queries. It was possible to pass
 parameters to `WP_Query` that would be different but would result in the
 same database query being generated. As the cache key is generated from a
 mixture of query arguments and the SQL query, this resulted in different
 cache keys for the same database query, resulting in unnecessary duplicate
 queries. In this change, the logic in the `generate_cache_key` method has
 been improved to ensure reuse of existing caches. The following edge cases
 have been considered:

 - Passing `post_type` as an empty string.
 - Passing `post_type` as the string `any`.
 - Passing `post_type` as array vs. string.
 - Passing `post_type` as an array in a different order.
 - Not passing `orderby`.
 - Passing `post_status` as an array vs. string.
 - Passing `post_status` as an array in a different order.

 This change also fixes an issue where the old SQL query would not match,
 as the queries had different whitespaces.

 Props spacedmonkey, joemcgill, pbearne, peterwilsoncc, rajinsharwar,
 mukesh27, thekt12, huzaifaalmesbah, rodionov201.
 Fixes #59442.
 }}}

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


More information about the wp-trac mailing list