diff options
-rw-r--r-- | lib/class/stream.class.php | 21 | ||||
-rw-r--r-- | 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 @@ -139,6 +139,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 * agent and IP also do a little GC in this function @@ -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'; |