From be2be64b993aff2a330394d5de6307455f48fa41 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 19 Apr 2006 02:53:02 +0000 Subject: [PATCH] Remove comment_count_cache. fixes #2670 git-svn-id: https://develop.svn.wordpress.org/trunk@3716 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment-template.php | 80 ++++++++++++++++---------------- wp-includes/functions.php | 3 +- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index ce89d5c507..1455f89888 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -142,17 +142,19 @@ function comments_link( $file = '', $echo = true ) { } function get_comments_number( $post_id = 0 ) { - global $wpdb, $comment_count_cache, $id; + global $wpdb, $id; $post_id = (int) $post_id; if ( !$post_id ) $post_id = $id; - // TODO: Remove SELECT. Use get_post(). - if ( !isset($comment_count_cache[$post_id]) ) - $comment_count_cache[$id] = $wpdb->get_var("SELECT comment_count FROM $wpdb->posts WHERE ID = '$post_id'"); + $post = get_post($post_id); + if ( ! isset($post->comment_count) ) + $count = 0; + else + $count = $post->comment_count; - return apply_filters('get_comments_number', $comment_count_cache[$post_id]); + return apply_filters('get_comments_number', $count); } function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) { @@ -323,48 +325,46 @@ function comments_popup_script($width=400, $height=400, $file='') { function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; - global $comment_count_cache; - if (! is_single() && ! is_page()) { - // TODO: Use API instead of SELECT - 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';"); + if ( is_single() || is_page() ) + return; - $number = $comment_count_cache[$id]; + $number = get_comments_number($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; return; - } else { - if (!empty($post->post_password)) { // if there's a password - if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie - echo(__('Enter your password to view comments')); - return; - } - } - echo ''; - comments_number($zero, $one, $more, $number); - echo ''; } + + if ( !empty($post->post_password) ) { // if there's a password + if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie + echo(__('Enter your password to view comments')); + return; + } } + + echo ''; + comments_number($zero, $one, $more, $number); + echo ''; } ?> diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 5d0750e2c1..e8b31624d2 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1313,7 +1313,7 @@ function update_post_category_cache($post_ids) { } function update_post_caches(&$posts) { - global $post_cache, $category_cache, $comment_count_cache, $post_meta_cache; + global $post_cache, $category_cache, $post_meta_cache; global $wpdb; // No point in doing all this work if we didn't match any posts. @@ -1324,7 +1324,6 @@ function update_post_caches(&$posts) { for ($i = 0; $i < count($posts); $i++) { $post_id_array[] = $posts[$i]->ID; $post_cache[$posts[$i]->ID] = &$posts[$i]; - $comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count; } $post_id_list = implode(',', $post_id_array);