Commit f01bd675 authored by Dries's avatar Dries

- Performance improvement: made 'sid' the primary key of the sessions table.
  That should improve performance of session handling as well improve
  performance of the "Who's online"-block.  Drupal.org's sessions table
  contains appr. 40.000 sessions on a slow day and rendering the "Who's
  online"-block became a performance bottleneck.

  This change has yet to be tested on a busy site so things might go wrong.
parent 7a5884cd
......@@ -567,7 +567,7 @@ CREATE TABLE sessions (
timestamp int(11) NOT NULL default '0',
session longtext,
KEY uid (uid),
KEY sid (sid),
PRIMARY KEY sid (sid),
KEY timestamp (timestamp)
) TYPE=MyISAM;
......
......@@ -86,7 +86,8 @@
"2004-09-17" => "update_107",
"2004-10-16" => "update_108",
"2004-10-18" => "update_109",
"2004-10-31: first update since Drupal 4.5.0 release" => "update_110"
"2004-10-31: first update since Drupal 4.5.0 release" => "update_110",
"2004-11-07" => "update_111"
);
function update_32() {
......@@ -1966,6 +1967,16 @@ function update_110() {
return $ret;
}
function update_111() {
$ret = array();
if ($GLOBALS['db_type'] == 'mysql') {
$ret[] = update_sql('ALTER TABLE {sessions} ADD PRIMARY KEY sid (sid)');
}
return $ret;
}
function update_sql($sql) {
$edit = $_POST["edit"];
$result = db_query($sql);
......
......@@ -25,8 +25,8 @@ function sess_read($key) {
$result = db_query_range("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s' AND u.status < 3", $key, 0, 1);
if (!db_num_rows($result)) {
$result = db_query("SELECT u.* FROM {users} u WHERE u.uid = 0");
db_query("INSERT INTO {sessions} (uid, sid, hostname, timestamp) values(%d, '%s', '%s', %d)", $user->uid, $key, $_SERVER["REMOTE_ADDR"], time());
$result = db_query("SELECT u.* FROM {users} u WHERE u.uid = 0");
}
$user = db_fetch_object($result);
......
......@@ -563,7 +563,7 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
$time_period = variable_get('user_block_seconds_online', 2700);
// Perform database queries to gather online user lists.
$guests = db_fetch_object(db_query('SELECT COUNT(DISTINCT(sid)) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
$guests = db_fetch_object(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
$users = db_query('SELECT DISTINCT(uid), MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC', time() - $time_period );
$total_users = db_num_rows($users);
......
......@@ -563,7 +563,7 @@ function user_block($op = 'list', $delta = 0, $edit = array()) {
$time_period = variable_get('user_block_seconds_online', 2700);
// Perform database queries to gather online user lists.
$guests = db_fetch_object(db_query('SELECT COUNT(DISTINCT(sid)) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
$guests = db_fetch_object(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
$users = db_query('SELECT DISTINCT(uid), MAX(timestamp) AS max_timestamp FROM {sessions} WHERE timestamp >= %d AND uid != 0 GROUP BY uid ORDER BY max_timestamp DESC', time() - $time_period );
$total_users = db_num_rows($users);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment