From a2740628bb1dcfaa84d00ac05a80a92afdaffbd6 Mon Sep 17 00:00:00 2001 From: alecpl <alec@alec.pl> Date: Thu, 02 Oct 2008 03:09:48 -0400 Subject: [PATCH] - improved rcube_sess_gc() when enable_caching=false, also use join() once --- program/include/session.inc | 52 ++++++++++++++++++++++++++++------------------------ 1 files changed, 28 insertions(+), 24 deletions(-) diff --git a/program/include/session.inc b/program/include/session.inc index f9b7f86..d6486a4 100644 --- a/program/include/session.inc +++ b/program/include/session.inc @@ -128,36 +128,40 @@ 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'); - - if (sizeof($exp_sessions)) { - // delete session cache records - if ($caching) { - $DB->query("DELETE FROM " . get_table_name('cache') . " - WHERE session_id IN ('".join("','", $exp_sessions)."')"); + $exp_sessions = array(); + while ($sql_arr = $DB->fetch_assoc($sql_result)) { + $exp_sessions[] = $sql_arr['sess_id']; } - // delete session records + 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 (" . $exp_sessions . ")"); + + // delete session records + $DB->query("DELETE FROM " . get_table_name('session') . " + WHERE sess_id IN (" . $exp_sessions . ")"); + } + + // 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; -- Gitblit v1.9.1