diff options
Diffstat (limited to 'program/include')
-rw-r--r-- | program/include/session.inc | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/program/include/session.inc b/program/include/session.inc index f9b7f86a4..d6486a43a 100644 --- a/program/include/session.inc +++ b/program/include/session.inc @@ -128,36 +128,40 @@ function rcube_sess_gc($maxlifetime) return false; } - // get all expired sessions - $sql_result = $DB->query( - "SELECT sess_id - FROM " . get_table_name('session') . " - WHERE " . $DB->unixtimestamp($DB->now())."-".$DB->unixtimestamp('changed') . " > ?", - $maxlifetime); + if ($rcmail->config->get('enable_caching')) { + // get all expired sessions + $sql_result = $DB->query( + "SELECT sess_id + FROM " . get_table_name('session') . " + WHERE " . $DB->unixtimestamp($DB->now())."-".$DB->unixtimestamp('changed') . " > ?", + $maxlifetime); - $exp_sessions = array(); - while ($sql_arr = $DB->fetch_assoc($sql_result)) { - $exp_sessions[] = $sql_arr['sess_id']; - } - - $caching = $rcmail->config->get('enable_caching'); + $exp_sessions = array(); + while ($sql_arr = $DB->fetch_assoc($sql_result)) { + $exp_sessions[] = $sql_arr['sess_id']; + } - if (sizeof($exp_sessions)) { - // delete session cache records - if ($caching) { + if (sizeof($exp_sessions)) { + $exp_sessions = "'" . join("','", $exp_sessions) . "'"; + // delete session cache records $DB->query("DELETE FROM " . get_table_name('cache') . " - WHERE session_id IN ('".join("','", $exp_sessions)."')"); + WHERE session_id IN (" . $exp_sessions . ")"); + + // delete session records + $DB->query("DELETE FROM " . get_table_name('session') . " + WHERE sess_id IN (" . $exp_sessions . ")"); } - // delete session records + // also run message cache GC + rcmail_message_cache_gc(); + + } else { + // just delete all expired sessions $DB->query("DELETE FROM " . get_table_name('session') . " - WHERE sess_id IN ('".join("','", $exp_sessions)."')"); + WHERE " . $DB->unixtimestamp($DB->now())."-".$DB->unixtimestamp('changed') . " > ?", + $maxlifetime); } - // also run message cache GC - if ($caching) { - rcmail_message_cache_gc(); - } rcmail_temp_gc(); return true; |