WordPress.org

Make WordPress Core

Changeset 5135


Ignore:
Timestamp:
03/29/2007 01:39:05 AM (11 years ago)
Author:
rob1n
Message:

Speed (wp_)list_authors by consolidating some queries. Props graeme. fixes #1659

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/author-template.php

    r5087 r5135  
    174174
    175175function wp_list_authors($args = '') {
     176    global $wpdb;
     177   
    176178    if ( is_array($args) )
    177179        $r = &$args;
     
    183185    $r = array_merge($defaults, $r);
    184186    extract($r);
    185 
    186     global $wpdb;
     187   
    187188    // TODO:  Move select to get_authors().
    188     $query = "SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name";
    189     $authors = $wpdb->get_results($query);
     189    $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
     190   
     191    $author_count = array();
     192    foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_status = 'publish' GROUP BY post_author") as $row) {
     193        $author_count[$row->post_author] = $row->count;
     194    }
    190195
    191196    foreach ( (array) $authors as $author ) {
    192197        $author = get_userdata( $author->ID );
    193         $posts = get_usernumposts($author->ID);
     198        $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
    194199        $name = $author->nickname;
    195200
Note: See TracChangeset for help on using the changeset viewer.