From 16a3144b00b648e2af9551cb7c740c0e17a52538 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sat, 9 Apr 2005 07:09:26 +0000 Subject: [PATCH] Use comment count cache. git-svn-id: https://develop.svn.wordpress.org/trunk@2522 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment-functions.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php index e39709a04f..300df69695 100644 --- a/wp-includes/comment-functions.php +++ b/wp-includes/comment-functions.php @@ -42,11 +42,10 @@ function clean_url( $url ) { function get_comments_number( $comment_id ) { global $wpdb, $comment_count_cache; $comment_id = (int) $comment_id; - if (!isset($comment_count_cache[$comment_id])) - $number = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'"); - else - $number = $comment_count_cache[$comment_id]; - return apply_filters('get_comments_number', $number); + if (!isset($comment_count_cache[$comment_id])) + $comment_count_cache[$comment_id] = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'"); + + return apply_filters('get_comments_number', $comment_count_cache[$comment_id]); } function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) { @@ -94,11 +93,11 @@ function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Com global $comment_count_cache; if (! is_single() && ! is_page()) { - if ('' == $comment_count_cache["$id"]) { - $number = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';"); - } else { - $number = $comment_count_cache["$id"]; - } + if ( !isset($comment_count_cache[$id])) + $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';"); + + $number = $comment_count_cache[$id]; + if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) { echo $none; return;