Make WordPress Core

Changeset 10090


Ignore:
Timestamp:
12/06/2008 09:23:36 PM (18 years ago)
Author:
azaozz
Message:

Improve the recent comments dashboard widget, props matt, fixes #8510

File:
1 edited

Legend:

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

    r10080 r10090  
    405405
    406406        // 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" );
     407        $comments = array();
     408        $start = 0;
     409
     410        while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments ORDER BY comment_date_gmt DESC LIMIT $start, 50" ) ) {
     411
     412                foreach ( $possible as $comment ) {
     413                        if ( count( $comments ) >= 5 )
     414                                break;
     415                        if ( in_array( $comment->comment_approved, $allowed_states ) )
     416                                $comments[] = $comment;
     417                }
     418
     419                $start = $start + 50;
     420        }
    408421
    409422        if ( $comments ) :
    … …  
    412425                <div id="the-comment-list" class="list:comment">
    413426<?php
    414                 $count = 0;
    415                 foreach ( $comments as $comment ) {
    416                         if ( $count >= 5 )
    417                                 break;
    418                         if ( in_array($comment->comment_approved, $allowed_states) )
    419                                 _wp_dashboard_recent_comments_row( $comment );
    420                         $count++;
    421                 }
     427                foreach ( $comments as $comment )
     428                        _wp_dashboard_recent_comments_row( $comment );
    422429?>
    423430
Note: See TracChangeset for help on using the changeset viewer.