Make WordPress Core


Ignore:
Timestamp:
04/09/2005 07:09:26 AM (21 years ago)
Author:
ryan
Message:

Use comment count cache.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment-functions.php

    r2518 r2522  
    4343        global $wpdb, $comment_count_cache;
    4444        $comment_id = (int) $comment_id;
    45         if (!isset($comment_count_cache[$comment_id]))
    46                 $number =  $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'");
    47         else
    48                 $number =  $comment_count_cache[$comment_id];
    49         return apply_filters('get_comments_number', $number);
     45        if (!isset($comment_count_cache[$comment_id]))
     46                $comment_count_cache[$comment_id] =  $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_id' AND comment_approved = '1'");
     47       
     48        return apply_filters('get_comments_number', $comment_count_cache[$comment_id]);
    5049}
    5150
     
    9594
    9695        if (! is_single() && ! is_page()) {
    97     if ('' == $comment_count_cache["$id"]) {
    98         $number = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");
    99     } else {
    100         $number = $comment_count_cache["$id"];
    101     }
     96    if ( !isset($comment_count_cache[$id]))
     97                        $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");
     98
     99                $number = $comment_count_cache[$id];
     100
    102101    if (0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status) {
    103102        echo $none;
Note: See TracChangeset for help on using the changeset viewer.