[wp-trac] [WordPress Trac] #57373: WP_Query loading posts twice.

WordPress Trac noreply at wordpress.org
Thu Dec 22 15:53:09 UTC 2022


#57373: WP_Query loading posts twice.
--------------------------+-----------------------
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  6.1.2
Component:  Query         |    Version:  6.1
 Severity:  normal        |   Keywords:  has-patch
  Focuses:  performance   |
--------------------------+-----------------------
 So in [54352] how posts are primed in caches are changed. This introduced
 a bug. In many cases, posts are primed using split query. This results in
 posts being primed using _prime_post_caches and a split query. But for
 queries that are unlimited, like if you pass post_per_page = -1. Posts are
 loaded but not primed in caches. So this results in the following.

 1. Post objects are loading via a database query to select * from
 wp_posts.
 2. Then in line 3459, _prime_post_cache, is called again, doing another
 database query.

 This is wasteful, as the posts are already in memory and should referenced
 like that.

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


More information about the wp-trac mailing list