From f0f191c0786c329ca30bdfaa7a15fdc10fd2f5a9 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Tue, 31 Jul 2007 18:12:12 +0000 Subject: slight tweak to do gcing a little more often, might scale this back later --- lib/class/stream.class.php | 21 +++++++++++++++++++-- lib/stream.lib.php | 4 ++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index fe40de79..d13271dd 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -138,6 +138,24 @@ class Stream { } // session_exists + /** + * gc_session + * This function performes the garbage collection stuff, run on extend and on now playing refresh + */ + public static function gc_session($ip='',$agent='',$uid='',$sid='') { + + $time = time(); + $sql = "DELETE FROM `session_stream` WHERE `expire` < '$time'"; + $db_results = Dba::query($sql); + + // We need all of this to run this query + if ($ip AND $agent AND $uid AND $sid) { + $sql = "DELETE FROM `session_stream` WHERE `ip`='$ip' AND `agent`='$agent' AND `user`='$uid' AND `id` != '$sid'"; + $db_results = Dba::query($sql); + } + + } // gc_session + /** * extend_session * This takes the passed sid and does a replace into also setting the user @@ -155,8 +173,7 @@ class Stream { "WHERE `id`='$sid'"; $db_results = Dba::query($sql); - $sql = "DELETE FROM `session_stream` WHERE `ip`='$ip' AND `agent`='$agent' AND `user`='$uid' AND `id` != '$sid'"; - $db_results = Dba::query($sql); + self::gc_session($ip,$agent,$uid,$sid); return true; diff --git a/lib/stream.lib.php b/lib/stream.lib.php index df07e821..745d1140 100644 --- a/lib/stream.lib.php +++ b/lib/stream.lib.php @@ -80,6 +80,10 @@ function clear_now_playing() { */ function show_now_playing() { + // GC! + Stream::gc_session(); + gc_now_playing(); + $web_path = Config::get('web_path'); $results = get_now_playing(); require Config::get('prefix') . '/templates/show_now_playing.inc.php'; -- cgit