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

git-svn-id: https://develop.svn.wordpress.org/trunk@10422 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2009-01-23 22:26:40 +00:00
parent 3e4d81f29e
commit 0f0b2c2c9e

View File

@ -1920,17 +1920,24 @@ function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0
$start = abs( (int) $start );
$num = (int) $num;
$post = (int) $post;
$count = wp_count_comments();
if ( 'moderated' == $status )
if ( 'moderated' == $status ) {
$approved = "comment_approved = '0'";
elseif ( 'approved' == $status )
$total = $count->moderated;
} elseif ( 'approved' == $status ) {
$approved = "comment_approved = '1'";
elseif ( 'spam' == $status )
$total = $count->approved;
} elseif ( 'spam' == $status ) {
$approved = "comment_approved = 'spam'";
else
$total = $count->spam;
} else {
$approved = "( comment_approved = '0' OR comment_approved = '1' )";
$total = $count->moderated + $count->approved;
}
if ( $post ) {
$total = '';
$post = " AND comment_post_ID = '$post'";
$orderby = "ORDER BY comment_date_gmt ASC LIMIT $start, $num";
} else {
@ -1949,9 +1956,13 @@ function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0
else
$typesql = '';
if ( !empty($type) )
$total = '';
if ( $s ) {
$total = '';
$s = $wpdb->escape($s);
$comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE
$query = "FROM $wpdb->comments WHERE
(comment_author LIKE '%$s%' OR
comment_author_email LIKE '%$s%' OR
comment_author_url LIKE ('%$s%') OR
@ -1959,14 +1970,16 @@ function _wp_get_comment_list( $status = '', $s = false, $start, $num, $post = 0
comment_content LIKE ('%$s%') ) AND
$approved
$typesql
$orderby");
$orderby";
} else {
$comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE $approved $post $typesql $orderby" );
$query = "FROM $wpdb->comments USE INDEX (comment_date_gmt) WHERE $approved $post $typesql $orderby";
}
update_comment_cache($comments);
$comments = $wpdb->get_results("SELECT * $query");
if ( '' === $total )
$total = $wpdb->get_var("SELECT COUNT(comment_ID) $query");
$total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
update_comment_cache($comments);
return array($comments, $total);
}