summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2003-02-01 20:01:43 +0000
committerDries Buytaert <dries@buytaert.net>2003-02-01 20:01:43 +0000
commit6746ee41f57e842799a1410ad015d74189e70d36 (patch)
treee8f95cf15545c4254a1453aba5d024f8eb31f613
parentcfd31c93f1f4a4453f7f67e9bf5d3826f9cfce2f (diff)
downloadbrdo-6746ee41f57e842799a1410ad015d74189e70d36.tar.gz
brdo-6746ee41f57e842799a1410ad015d74189e70d36.tar.bz2
- Added some caching. Patch by Moshe.
-rw-r--r--modules/comment.module29
-rw-r--r--modules/comment/comment.module29
2 files changed, 40 insertions, 18 deletions
diff --git a/modules/comment.module b/modules/comment.module
index 4f991b706..88c2ee7c9 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 4f991b706..88c2ee7c9 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 {