Remove slow left join pending better solution. see #4529

git-svn-id: http://svn.automattic.com/wordpress/trunk@12116 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-10-27 15:51:58 +00:00
parent aac51df0e9
commit 0dd4b4ab9e

View File

@ -766,12 +766,11 @@ function wp_count_comments( $post_id = 0 ) {
if ( false !== $count ) if ( false !== $count )
return $count; return $count;
$where = 'WHERE '; $where = '';
if( $post_id > 0 ) if ( $post_id > 0 )
$where .= $wpdb->prepare( "c.comment_post_ID = %d AND ", $post_id ); $where = $wpdb->prepare( "comment_post_ID = %d AND ", $post_id );
$where .= "p.post_status <> 'trash'";
$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; $total = 0;
$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash'); $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash');