- 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.
parent
3613729d4f
commit
df2e5ef505
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue