- Added some caching. Patch by Moshe.

4.2.x
Dries Buytaert 2003-02-01 20:01:43 +00:00
parent cfd31c93f1
commit 6746ee41f5
2 changed files with 40 additions and 18 deletions

View File

@ -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 {

View File

@ -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 {