From 93add5ad77889ff5369cbc1e1b4e7d0573d5e7c0 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 20 Oct 2003 21:35:35 +0000 Subject: - Simplified comment counter caches a bit: removed some redundant SQL code. Maybe this will fix Jeremy's "phantom comments". --- modules/comment.module | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'modules/comment.module') diff --git a/modules/comment.module b/modules/comment.module index 1f048fc40..e038285e2 100644 --- a/modules/comment.module +++ b/modules/comment.module @@ -1502,21 +1502,19 @@ function comment_num_all($nid) { static $cache; if (!isset($cache[$nid])) { - $comment = db_fetch_object(db_query("SELECT COUNT(nid) AS number FROM {comments} WHERE nid = %d AND status = 0 GROUP BY nid", $nid)); - $cache[$nid] = $comment->number ? $comment->number : 0; + $cache[$nid] = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE nid = %d AND status = 0", $nid)); } return $cache[$nid]; } -function comment_num_replies($id) { +function comment_num_replies($pid) { static $cache; - if (!isset($cache[$id])) { - $result = db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND status = 0", $id); - $cache[$id] = $result ? db_result($result, 0) : 0; + if (!isset($cache[$pid])) { + $cache[$pid] = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND status = 0", $pid)); } - return $cache[$id]; + return $cache[$pid]; } /** -- cgit v1.2.3