Use comment count cache.

git-svn-id: http://svn.automattic.com/wordpress/trunk@2522 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-04-09 07:09:26 +00:00
parent 6bd9d5a824
commit f81f76f751
1 changed files with 9 additions and 10 deletions

View File

@ -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;