Make WordPress Core

Ticket #17025: 17025.optimizeforeach.diff

File 17025.optimizeforeach.diff, 834 bytes (added by Mte90, 8 years ago)

optimized foreach moving query outside

  • wp-includes/author-template.php

     
    380380        $authors = get_users( $query_args );
    381381
    382382        $author_count = array();
    383         foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) {
     383     
     384      $rows = $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" );
     385     
     386        foreach ( $rows as $row ) {
    384387                $author_count[$row->post_author] = $row->count;
    385388        }
    386389        foreach ( $authors as $author_id ) {