WordPress.org

Make WordPress Core

Ticket #14222: 14222.patch

File 14222.patch, 1.4 KB (added by Viper007Bond, 8 years ago)

Move the allowed states check from PHP into MySQL

  • wp-admin/includes/dashboard.php

     
    523523        global $wpdb;
    524524
    525525        if ( current_user_can('edit_posts') )
    526                 $allowed_states = array('0', '1');
     526                $allowed_states = 'AND c.comment_approved IN (0,1)';
    527527        else
    528                 $allowed_states = array('1');
     528                $allowed_states = 'AND c.comment_approved = 1';
    529529
    530530        // Select all comment types and filter out spam later for better query performance.
    531531        $comments = array();
     
    537537        else
    538538                $total_items = 5;
    539539
    540         while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
     540        while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' $allowed_states ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
    541541
    542542                foreach ( $possible as $comment ) {
    543543                        if ( count( $comments ) >= $total_items )
    544544                                break;
    545                         if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
     545                        if ( current_user_can( 'read_post', $comment->comment_post_ID ) )
    546546                                $comments[] = $comment;
    547547                }
    548548