summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-07-13 20:44:13 +0000
committerDries Buytaert <dries@buytaert.net>2004-07-13 20:44:13 +0000
commitdf2e5ef505d954230956a4109aebf72198e4a3f4 (patch)
treebf4288892f8b90c95b9280bcc6d72df1913cb06e
parent3613729d4f1ad8675305445e2717856b2c377faa (diff)
downloadbrdo-df2e5ef505d954230956a4109aebf72198e4a3f4.tar.gz
brdo-df2e5ef505d954230956a4109aebf72198e4a3f4.tar.bz2
- Patch #8942 by Morbus: when testing under devel.module, the "SELECT timestamp from {history}" SQL statement is executed multiple times in two different functions. This duplicated code should be placed in a function, and that's been done already with node_last_visited() - the remaining code was just never updated to use the new routine. This patch changes the old code to use node_last_visited, and also modifies node_last_visited() to cache the result of the database call.
-rw-r--r--modules/node.module14
-rw-r--r--modules/node/node.module14
2 files changed, 16 insertions, 12 deletions
diff --git a/modules/node.module b/modules/node.module
index af41ab7a2..4044d64cd 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -104,8 +104,7 @@ function node_tag_new($nid) {
global $user;
if ($user->uid) {
- $result = db_query('SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d', $user->uid, $nid);
- if (db_fetch_object($result)) {
+ if (node_last_viewed($nid)) {
db_query('UPDATE {history} SET timestamp = %d WHERE uid = %d AND nid = %d', time(), $user->uid, $nid);
}
else {
@@ -120,9 +119,13 @@ function node_tag_new($nid) {
*/
function node_last_viewed($nid) {
global $user;
+ static $history;
- $history = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = '$user->uid' AND nid = %d", $nid));
- return ($history->timestamp ? $history->timestamp : NODE_NEW_LIMIT);
+ if (!isset($history[$nid])) {
+ $history[$nid] = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = '$user->uid' AND nid = %d", $nid));
+ }
+
+ return ($history[$nid]->timestamp ? $history[$nid]->timestamp : 0);
}
/**
@@ -140,8 +143,7 @@ function node_is_new($nid, $timestamp) {
if (!isset($cache[$nid])) {
if ($user->uid) {
- $history = db_fetch_object(db_query('SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d', $user->uid, $nid));
- $cache[$nid] = $history->timestamp ? $history->timestamp : 0;
+ $cache[$nid] = node_last_viewed($nid);
}
else {
$cache[$nid] = time();
diff --git a/modules/node/node.module b/modules/node/node.module
index af41ab7a2..4044d64cd 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -104,8 +104,7 @@ function node_tag_new($nid) {
global $user;
if ($user->uid) {
- $result = db_query('SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d', $user->uid, $nid);
- if (db_fetch_object($result)) {
+ if (node_last_viewed($nid)) {
db_query('UPDATE {history} SET timestamp = %d WHERE uid = %d AND nid = %d', time(), $user->uid, $nid);
}
else {
@@ -120,9 +119,13 @@ function node_tag_new($nid) {
*/
function node_last_viewed($nid) {
global $user;
+ static $history;
- $history = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = '$user->uid' AND nid = %d", $nid));
- return ($history->timestamp ? $history->timestamp : NODE_NEW_LIMIT);
+ if (!isset($history[$nid])) {
+ $history[$nid] = db_fetch_object(db_query("SELECT timestamp FROM {history} WHERE uid = '$user->uid' AND nid = %d", $nid));
+ }
+
+ return ($history[$nid]->timestamp ? $history[$nid]->timestamp : 0);
}
/**
@@ -140,8 +143,7 @@ function node_is_new($nid, $timestamp) {
if (!isset($cache[$nid])) {
if ($user->uid) {
- $history = db_fetch_object(db_query('SELECT timestamp FROM {history} WHERE uid = %d AND nid = %d', $user->uid, $nid));
- $cache[$nid] = $history->timestamp ? $history->timestamp : 0;
+ $cache[$nid] = node_last_viewed($nid);
}
else {
$cache[$nid] = time();