diff --git a/modules/comment.module b/modules/comment.module index 4f991b70612..88c2ee7c96b 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -1319,13 +1319,24 @@ function comment_settings($mode, $order, $threshold, $comments_per_page) { } function comment_num_all($nid) { - $comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '%d' AND c.status = 0 GROUP BY n.nid", $nid)); - return $comment->number ? $comment->number : 0; + static $cache; + + if (empty($cache[$nid])) { + $comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '%d' AND c.status = 0 GROUP BY n.nid", $nid)); + $cache[$nid] = $comment->number ? $comment->number : 0; + } + return $cache[$nid]; } function comment_num_replies($id) { - $result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = '%d' AND status = 0", $id); - return ($result) ? db_result($result, 0) : 0; + static $cache; + + if (empty($cache[$nid])) { + $result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = '%d' AND status = 0", $id); + $cache[$nid] = ($result) ? db_result($result, 0) : 0; + } + + return $num_replies[$nid]; } /** @@ -1381,19 +1392,19 @@ function comment_tag_new($nid) { function comment_is_new($comment) { global $user; - static $date; + static $cache; - if (!$date[$comment->nid]) { + if (!$cache[$comment->nid]) { if ($user->uid) { $history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = '$user->uid' AND nid = '%d'", $comment->nid)); - $date[$comment->nid] = $history->timestamp ? $history->timestamp : 0; + $cache[$comment->nid] = $history->timestamp ? $history->timestamp : 0; } else { - $date[$comment->nid] = time(); + $cache[$comment->nid] = time(); } } - if ($comment->timestamp > $date[$comment->nid]) { + if ($comment->timestamp > $cache[$comment->nid]) { return 1; } else { diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 4f991b70612..88c2ee7c96b 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1319,13 +1319,24 @@ function comment_settings($mode, $order, $threshold, $comments_per_page) { } function comment_num_all($nid) { - $comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '%d' AND c.status = 0 GROUP BY n.nid", $nid)); - return $comment->number ? $comment->number : 0; + static $cache; + + if (empty($cache[$nid])) { + $comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '%d' AND c.status = 0 GROUP BY n.nid", $nid)); + $cache[$nid] = $comment->number ? $comment->number : 0; + } + return $cache[$nid]; } function comment_num_replies($id) { - $result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = '%d' AND status = 0", $id); - return ($result) ? db_result($result, 0) : 0; + static $cache; + + if (empty($cache[$nid])) { + $result = db_query("SELECT COUNT(cid) FROM comments WHERE pid = '%d' AND status = 0", $id); + $cache[$nid] = ($result) ? db_result($result, 0) : 0; + } + + return $num_replies[$nid]; } /** @@ -1381,19 +1392,19 @@ function comment_tag_new($nid) { function comment_is_new($comment) { global $user; - static $date; + static $cache; - if (!$date[$comment->nid]) { + if (!$cache[$comment->nid]) { if ($user->uid) { $history = db_fetch_object(db_query("SELECT timestamp FROM history WHERE uid = '$user->uid' AND nid = '%d'", $comment->nid)); - $date[$comment->nid] = $history->timestamp ? $history->timestamp : 0; + $cache[$comment->nid] = $history->timestamp ? $history->timestamp : 0; } else { - $date[$comment->nid] = time(); + $cache[$comment->nid] = time(); } } - if ($comment->timestamp > $date[$comment->nid]) { + if ($comment->timestamp > $cache[$comment->nid]) { return 1; } else {