[wp-trac] [WordPress Trac] #58599: WP_Query->get_posts: cache updated also when query is set to be not cacheable

WordPress Trac noreply at wordpress.org
Mon Jul 17 02:26:42 UTC 2023


#58599: WP_Query->get_posts: cache updated also when query is set to be not
cacheable
--------------------------+------------------------------
 Reporter:  saulirajala   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  6.2
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  performance
--------------------------+------------------------------
Changes (by peterwilsoncc):

 * version:  6.2.2 => 6.2


Comment:

 I think this is a bug introduced in [55035] /
 [https://github.com/WordPress/wordpress-
 develop/commit/5a497225b286964ff9302a21272731172840ed05 git 5a497225b2869]
 for #57373.

 Prior to the change, the IDs would be used to prime the cache and an
 additional query made to the database. After the change the returned post
 data was used to prime the cache.

 To ensure the cache contains all the expected data when the fields are
 modified, I think the code would need to be something like this:

 {{{#!php
 <?php
 if ( $q['cache_results'] ) {
         if ( $id_query_is_cacheable ) {
                 update_post_caches( $this->posts, $post_type,
 $q['update_post_term_cache'], $q['update_post_meta_cache'] );
         } else {
                 $post_ids = wp_list_pluck( $this->posts, 'ID' );
                 _prime_post_caches( $post_ids,
 $q['update_post_term_cache'], $q['update_post_meta_cache'] );
         }
 }

 }}}

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


More information about the wp-trac mailing list