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

WordPress Trac wp-trac at lists.automattic.com
Sat Mar 19 12:12:05 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):

 An implementation of lazy loading of the comment meta, which requires a
 bit of juggling due to the fact that this is being implemented as an
 external dropin.

 {{{
 class Lazy_Load_Comment_Meta {
         var $last_comment_query_ids = array();
         function __construct() {
                 add_filter('get_comment_metadata', array(&$this,
 'lazy_load_comment_metadata'), 100, 2);
                 add_filter('the_comments', array(&$this,
 'lazy_load_comment_metadata_fillids'), 100);
                 add_filter('comments_array', array(&$this,
 'lazy_load_comment_metadata_fillids'), 100);
         }

         function lazy_load_comment_metadata($data, $object_id) {
                 if ( !wp_cache_get($object_id, 'comment_meta') ) {
                         if ( !empty($this->last_comment_query_ids) )
                                 update_meta_cache('comment',
 $this->last_comment_query_ids );
                 }
                 return null;
         }
         function lazy_load_comment_metadata_fillids($comments) {
                 foreach ( $comments as $c )
                         $this->last_comment_query_ids[] = $c->comment_ID;
                 return $comments;
         }
 }
 }}}

 Stack:
 {{{
 Front:
 comments_template, wp_list_comments, Walker->paged_walk,
 Walker_Comment->display_element, Walker->display_element,
 call_user_func_array, Walker_Comment->start_el, call_user_func,
 twentyten_comment, comment_text, get_comment_text, apply_filters,
 call_user_func_array, secret_hooked_function, get_comment_meta,
 get_metadata, apply_filters, call_user_func_array,
 Lazy_Load_Comment_Meta->lazy_load_comment_metadata, update_meta_cache

 Back:
 WP_Comments_List_Table->display,
 WP_List_Table->display_rows_or_placeholder, WP_List_Table->display_rows,
 WP_Comments_List_Table->single_row, WP_List_Table->single_row_columns,
 call_user_func, WP_Comments_List_Table->column_comment, comment_text,
 get_comment_text, apply_filters, call_user_func_array,
 secret_hooked_function, get_comment_meta, get_metadata, apply_filters,
 call_user_func_array, Lazy_Load_Comment_Meta->lazy_load_comment_metadata,
 update_meta_cache
 }}}

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


More information about the wp-trac mailing list