Use comment count cache.

git-svn-id: https://develop.svn.wordpress.org/trunk@2522 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2005-04-09 07:09:26 +00:00
parent e40774a349
commit 16a3144b00
1 changed files with 9 additions and 10 deletions

View File

@ -43,10 +43,9 @@ function get_comments_number( $comment_id ) {
global $wpdb, $comment_count_cache; global $wpdb, $comment_count_cache;
$comment_id = (int) $comment_id; $comment_id = (int) $comment_id;
if (!isset($comment_count_cache[$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'"); $comment_count_cache[$comment_id] = $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', $comment_count_cache[$comment_id]);
return apply_filters('get_comments_number', $number);
} }
function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) { 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; global $comment_count_cache;
if (! is_single() && ! is_page()) { if (! is_single() && ! is_page()) {
if ('' == $comment_count_cache["$id"]) { if ( !isset($comment_count_cache[$id]))
$number = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';"); $comment_count_cache[$id] = $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"]; $number = $comment_count_cache[$id];
}
if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) { if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) {
echo $none; echo $none;
return; return;