From e35b1799073d7d5ada58edf6b28a2b9375271941 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 27 Oct 2009 15:51:58 +0000 Subject: [PATCH] Remove slow left join pending better solution. see #4529 git-svn-id: https://develop.svn.wordpress.org/trunk@12116 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 082bd7c125..f03e4b008b 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -766,12 +766,11 @@ function wp_count_comments( $post_id = 0 ) { if ( false !== $count ) return $count; - $where = 'WHERE '; - if( $post_id > 0 ) - $where .= $wpdb->prepare( "c.comment_post_ID = %d AND ", $post_id ); - $where .= "p.post_status <> 'trash'"; + $where = ''; + if ( $post_id > 0 ) + $where = $wpdb->prepare( "comment_post_ID = %d AND ", $post_id ); - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} c LEFT JOIN {$wpdb->posts} p ON c.comment_post_ID = p.ID {$where} GROUP BY comment_approved", ARRAY_A ); + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); $total = 0; $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash');