[wp-trac] [WordPress Trac] #55463: Add a limit to _prime_*_cache functions

WordPress Trac noreply at wordpress.org
Fri Mar 25 12:18:11 UTC 2022

#55463: Add a limit to _prime_*_cache functions
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Cache API     |    Version:
 Severity:  normal        |   Keywords:  needs-patch good-first-bug
  Focuses:  performance   |
 The _prime_*_cache functions, like `_prime_post_cache` do a simple query
 to prime caches. This does a IN request to get all the objects. As we know
 the number of objects we wish returned, as have an array, we can add a
 simple LIMIT to the query to improve the performance of the query.


 $fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM
 $wpdb->posts WHERE ID IN (%s) LIMIT %d", implode( ',', $non_cached_ids ),
 count( $non_cached_ids ) ) );

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

More information about the wp-trac mailing list