[wp-trac] [WordPress Trac] #59593: Improve query class cache key generation for array values

WordPress Trac noreply at wordpress.org
Wed Oct 11 11:11:51 UTC 2023


#59593: Improve query class cache key generation for array values
--------------------------+----------------------------
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  Cache API     |    Version:
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+----------------------------
 n the current WordPress core, cache keys are generated for all query
 classes by serializing the array of query arguments to create a unique
 cache key. This mechanism works effectively for most cases, but it falls
 short when query classes support array values as arguments. An example of
 this is the post__in parameter in the WP_Query class.

 The issue arises when different orders of array values are used for the
 post__in argument while making essentially identical queries. In such
 cases, distinct cache keys are generated for queries that should ideally
 produce the same result.

 For instance, consider the following two queries:

 Example.

 {{{#!php
 get_posts(['post__in' => [123, 456] ]);
 get_posts(['post__in' => [456, 123] ]);
 }}}

 Both queries are conceptually identical and should return the same
 results. However, the current cache key generation system treats them as
 separate queries, leading to potential inefficiencies and unnecessary
 cache duplication.

 A more specific case where this issue can impact performance is the
 combination of the orderby parameter with the post__in parameter in a
 WP_Query. Depending on the order of array values, the cache query value
 may differ, even though the actual result remains the same.

 To address this issue, we propose enhancing the cache key generation
 process for query classes that support array values as arguments. This
 improvement will help ensure that functionally identical queries generate
 the same cache key, ultimately improving performance and cache efficiency.

 By addressing this limitation in cache key generation, WordPress can
 better optimize its caching mechanisms and provide a more efficient
 experience for developers and users.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59593>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list