WordPress.org

Make WordPress Core

Changeset 10079


Ignore:
Timestamp:
12/05/2008 11:42:06 PM (12 years ago)
Author:
ryan
Message:

Speed up Recent Comments dash module query

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/dashboard.php

    r10076 r10079  
    397397 */
    398398function wp_dashboard_recent_comments() {
    399     $status = ( current_user_can('edit_posts') ) ? '' : 'approved';
    400 
    401     list($comments, $total) = _wp_get_comment_list( $status, false, 0, 5 );
     399    global $wpdb;
     400
     401    if ( current_user_can('edit_posts') )
     402        $allowed_states = array('0', '1');
     403    else
     404        $allowed_states = array('1');
     405
     406    // Select all comment types and filter out spam later for better query performance.
     407    $comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT 0, 50" );
    402408
    403409    if ( $comments ) :
     
    406412        <div id="the-comment-list" class="list:comment">
    407413<?php
    408         foreach ( $comments as $comment )
    409             _wp_dashboard_recent_comments_row( $comment );
     414        foreach ( $comments as $comment ) {
     415            if ( in_array($comment->comment_approved, $allowed_states) )
     416                _wp_dashboard_recent_comments_row( $comment );
     417        }
    410418?>
    411419
Note: See TracChangeset for help on using the changeset viewer.