[wp-trac] Re: [WordPress Trac] #5407: Improve wp_list_authors efficiency

WordPress Trac wp-trac at lists.automattic.com
Sun May 10 16:05:52 GMT 2009


#5407: Improve wp_list_authors efficiency
--------------------------+-------------------------------------------------
 Reporter:  Bobcat        |       Owner:  anonymous     
     Type:  enhancement   |      Status:  new           
 Priority:  low           |   Milestone:  Future Release
Component:  Optimization  |     Version:  2.3.1         
 Severity:  normal        |    Keywords:  needs-patch   
--------------------------+-------------------------------------------------
Changes (by Denis-de-Bernardy):

  * keywords:  has-patch 2nd-opinion => needs-patch
  * priority:  normal => low


Comment:

 there are still inefficiencies in the suggested patch. the correct one to
 use is:

 {{{
         if ( $show_fullname ) {
                 $author_name_field = "CASE
                 WHEN TRIM(CONCAT(COALESCE(meta_first_name.meta_value, ''),
 COALESCE(meta_last_name.meta_value, ''))) <> ''
                 THEN
                         TRIM(CONCAT(COALESCE(meta_first_name.meta_value,
 ''), COALESCE(meta_last_name.meta_value, '')))
                 ELSE
                         $wpdb->users.display_name
                 END"
                 $author_name_join = "
                 LEFT JOIN $wpdb->usermeta as meta_first_name ON
 meta_first_name.user_id = $wpdb->users.ID AND meta_first_name.meta_key =
 'firstname'
                 LEFT JOIN $wpdb->usermeta as meta_last_name ON
 meta_last_name.user_id = $wpdb->users.ID AND meta_last_name.meta_key =
 'lastname'
                 ";
         } else {
                 $author_name_field = "$wpdb->users.display_name"
                 $author_name_join = "";
         }

         $authors = $wpdb->get_results("
                 SELECT $wpdb->users.ID, $wpdb->users.user_nicename,
 COUNT($wpdb->posts.ID) as author_count, $author_name_field as author_name
                 FROM $wpdb->users
                 " . ( !$hide_empty ? "LEFT " : '' ) . "JOIN $wpdb->posts
 ON $wpdb->posts.post_author = $wpdb->users.ID
                 $author_name_join
                 " . ( $exclude_admin ? "WHERE $wpdb->users.user_login <>
 'admin' " : '' ) . "
                 GROUP BY $wpdb->users.ID
                 ORDER BY $wpdb->users.display_name
                 ");
 }}}

 It'll then get all of the needed details in one go, without the clutter
 (why is the private_posts_sql in there anyway?).

 However, it's mostly pointless to do so without editing a few more
 functions. Specifically, get_author_feed_link() will then go on for a
 rampage because it'll get each author individually. an extra param
 (user_nicename) is needed to the function, in order to pass it to
 get_author_posts_url().

 the rest amounts to needing to rewrite the function as needed.

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


More information about the wp-trac mailing list