Skip to content
Permalink
Browse files

datalib:add_to_log() - avoid schema lookups, pace updates to user and…

… user_lastaccess

* All updates to user.lastaccess and user_lastaccess.timeaccess are paced to
60s of the last update on the same record -- this should reduce the heat
on those tables.

* Updates/inserts to user_lastaccess are down with raw SQL to avoid costly
schema lookups on every request.
  • Loading branch information...
martinlanghoff
martinlanghoff committed Sep 19, 2007
1 parent e1e1f49 commit a9fcd13a771206dd36fef12a3e0a79a5bac12bb2
Showing with 10 additions and 10 deletions.
  1. +10 −10 lib/datalib.php
@@ -1507,24 +1507,24 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user
}
/// Store lastaccess times for the current user, do not use in cron and other commandline scripts
/// only update the lastaccess/timeaccess fields only once every 60s
if (!empty($USER->id) && ($userid == $USER->id) && !defined('FULLME')) {
$db->Execute('UPDATE '. $CFG->prefix .'user
SET lastip=\''. $REMOTE_ADDR .'\', lastaccess=\''. $timenow .'\'
WHERE id = \''. $userid .'\' ');
WHERE id = \''. $userid .'\' AND '.$timenow.' - lastaccess > 60');
if ($courseid != SITEID && !empty($courseid)) {
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++;};
if ($record = get_record('user_lastaccess', 'userid', $userid, 'courseid', $courseid)) {
$record->timeaccess = $timenow;
return update_record('user_lastaccess', $record);
if ($ulid = get_field('user_lastaccess', 'id', 'userid', $userid, 'courseid', $courseid)) {
$db->Execute("UPDATE {$CFG->prefix}user_lastaccess
SET timeaccess=$timenow
WHERE id = $ulid AND $timenow - timeaccess > 60");
} else {
$record = new object;
$record->userid = $userid;
$record->courseid = $courseid;
$record->timeaccess = $timenow;
return insert_record('user_lastaccess', $record);
$db->Execute("INSERT INTO {$CFG->prefix}user_lastaccess
('userid', 'courseid', 'timeaccess')
VALUES ($userid, $courseid, $timenow)");
}
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++;};
}
}
}

0 comments on commit a9fcd13

Please sign in to comment.
You can’t perform that action at this time.