[wp-trac] [WordPress Trac] #16894: Bulk load Comment Meta upon access

WordPress Trac wp-trac at lists.automattic.com
Sat Mar 19 11:28:34 UTC 2011


#16894: Bulk load Comment Meta upon access
-------------------------------------+-----------------------------
 Reporter:  dd32                     |       Owner:
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Future Release
Component:  Performance              |     Version:  3.1
 Severity:  normal                   |  Resolution:
 Keywords:  needs-patch 2nd-opinion  |
-------------------------------------+-----------------------------

Comment (by dd32):

 Adding this to the code in question bulk loads the comment meta for all
 requests for comment meta (which is suitable for the site in question I'm
 working on):


 {{{
         add_filter('the_comments', 'cache_all_comment_meta', 100); //
 using get_comments()
         add_filter('comments_array', 'cache_all_comment_meta', 100); //
 using Direct SQL in comments_template()
         function cache_all_comment_meta($comments) {
                 $comment_ids = wp_list_pluck($comments, 'comment_ID');
                 update_meta_cache('comment', $comment_ids);
                 return $comments;
         }
 comments_template, apply_filters, call_user_func_array,
 cache_all_comment_meta, update_meta_cache #12 (0.7ms)
 SELECT comment_id, meta_key, meta_value FROM wp_commentmeta WHERE
 comment_id IN (4,5,6,7,34,35,36,37)
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16894#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list