Fixed: garbage collection firing of during install (don't even ask me how, but it happened to me)

Added: multi-table garbage collection for MySQL 4 for Paul to review :)


git-svn-id: file:///svn/phpbb/trunk@4672 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Ludovic Arnaud 2003-11-16 23:16:02 +00:00
parent f454196097
commit 4a81ebb7f8

View file

@ -173,7 +173,7 @@ class session
// Garbage collection ... remove old sessions updating user information // Garbage collection ... remove old sessions updating user information
// if necessary. It means (potentially) 11 queries but only infrequently // if necessary. It means (potentially) 11 queries but only infrequently
if ($current_time - $config['session_gc'] > $config['session_last_gc']) if ($current_time > $config['session_last_gc'] + $config['session_gc'] && defined('PHPBB_INSTALLED'))
{ {
$this->gc($current_time); $this->gc($current_time);
} }
@ -359,6 +359,42 @@ class session
{ {
global $db, $config; global $db, $config;
switch (SQL_LAYER)
{
case 'mysql4':
// Firstly, delete guest sessions
$sql = 'DELETE FROM ' . SESSIONS_TABLE . '
WHERE session_user_id = ' . ANONYMOUS . '
AND session_time < ' . ($current_time - $config['session_length']);
$db->sql_query($sql);
// Keep only the most recent session for each user
// Note: if the user is currently browsing the board, his
// last_visit field won't be updated, which I believe should be
// the normal behavior anyway
$db->sql_return_on_error(TRUE);
$sql = 'DELETE FROM ' . SESSIONS_TABLE . '
USING ' . SESSIONS_TABLE . ' s1, ' . SESSIONS_TABLE . ' s2
WHERE s1.session_user_id = s2.session_user_id
AND s1.session_time < s2.session_time';
$db->sql_query($sql);
$db->sql_return_on_error(FALSE);
// Update last visit time
$sql = 'UPDATE ' . USERS_TABLE. ' u, ' . SESSIONS_TABLE . ' s
SET u.user_lastvisit = s.session_time, u.user_lastpage = s.session_page
WHERE s.session_time < ' . ($current_time - $config['session_length']) . '
AND u.user_id = s.session_user_id';
$db->sql_query($sql);
// Delete everything else now
$sql = 'DELETE FROM ' . SESSIONS_TABLE . '
WHERE session_time < ' . ($current_time - $config['session_length']);
$db->sql_query($sql);
set_config('session_last_gc', $current_time);
break;
// Get expired sessions, only most recent for each user // Get expired sessions, only most recent for each user
$sql = 'SELECT session_user_id, session_page, MAX(session_time) AS recent_time $sql = 'SELECT session_user_id, session_page, MAX(session_time) AS recent_time
FROM ' . SESSIONS_TABLE . ' FROM ' . SESSIONS_TABLE . '
@ -401,6 +437,7 @@ class session
// called again to delete other sessions // called again to delete other sessions
set_config('session_last_gc', $current_time); set_config('session_last_gc', $current_time);
} }
}
return; return;
} }