Make WordPress Core

Changeset 10422


Ignore:
Timestamp:
01/23/2009 10:26:40 PM (16 years ago)
Author:
ryan
Message:

Eliminate SQL_CACLC_FOUND_ROWS for edit-comments.php query. Use results of earlier wp_count_comments() if appropriate otherwise perform COUNT query. see #7415

File:
1 edited

Legend:

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

    r10389 r10422  
    19211921    $num = (int) $num;
    19221922    $post = (int) $post;
    1923 
    1924     if ( 'moderated' == $status )
     1923    $count = wp_count_comments();
     1924
     1925    if ( 'moderated' == $status ) {
    19251926        $approved = "comment_approved = '0'";
    1926     elseif ( 'approved' == $status )
     1927        $total = $count->moderated;
     1928    } elseif ( 'approved' == $status ) {
    19271929        $approved = "comment_approved = '1'";
    1928     elseif ( 'spam' == $status )
     1930        $total = $count->approved;
     1931    } elseif ( 'spam' == $status ) {
    19291932        $approved = "comment_approved = 'spam'";
    1930     else
     1933        $total = $count->spam;
     1934    } else {
    19311935        $approved = "( comment_approved = '0' OR comment_approved = '1' )";
     1936        $total = $count->moderated + $count->approved;
     1937    }
    19321938
    19331939    if ( $post ) {
     1940        $total = '';
    19341941        $post = " AND comment_post_ID = '$post'";
    19351942        $orderby = "ORDER BY comment_date_gmt ASC LIMIT $start, $num";
     
    19501957        $typesql = '';
    19511958
     1959    if ( !empty($type) )
     1960        $total = '';
     1961
    19521962    if ( $s ) {
     1963        $total = '';
    19531964        $s = $wpdb->escape($s);
    1954         $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
     1965        $query = "FROM $wpdb->comments WHERE
    19551966            (comment_author LIKE '%$s%' OR
    19561967            comment_author_email LIKE '%$s%' OR
     
    19601971            $approved
    19611972            $typesql
    1962             $orderby");
     1973            $orderby";
    19631974    } else {
    1964         $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved $post $typesql $orderby" );
    1965     }
     1975        $query = "FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $approved $post $typesql $orderby";
     1976    }
     1977
     1978    $comments = $wpdb->get_results("SELECT * $query");
     1979    if ( '' === $total )
     1980        $total = $wpdb->get_var("SELECT COUNT(comment_ID) $query");
    19661981
    19671982    update_comment_cache($comments);
    1968 
    1969     $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
    19701983
    19711984    return array($comments, $total);
Note: See TracChangeset for help on using the changeset viewer.