X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FSession.php;h=79a69a96ea3dc11b1f93672890f1687f2e263fa0;hb=b1367ae8da8e67686f38c99b66c25fa049dbfba3;hp=93fd99baa817ee2a6ddd75c7e16b95094917f746;hpb=190d45cd05a1affbc8d0db50a487b5081f6a34cb;p=quix0rs-gnu-social.git diff --git a/classes/Session.php b/classes/Session.php index 93fd99baa8..79a69a96ea 100644 --- a/classes/Session.php +++ b/classes/Session.php @@ -2,8 +2,8 @@ /** * Table Definition for session * - * Laconica - a distributed open-source microblogging tool - * Copyright (C) 2009, Control Yourself, Inc. + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2009, StatusNet, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -if (!defined('LACONICA')) { exit(1); } +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; @@ -85,9 +85,18 @@ class Session extends Memcached_DataObject return $session->insert(); } else { - $session->session_data = $session_data; + if (strcmp($session->session_data, $session_data) == 0) { + self::logdeb("Not writing session '$id'; unchanged"); + return true; + } else { + self::logdeb("Session '$id' data changed; updating"); + + $orig = clone($session); - return $session->update(); + $session->session_data = $session_data; + + return $session->update($orig); + } } } @@ -106,16 +115,26 @@ class Session extends Memcached_DataObject { self::logdeb("garbage collection (maxlifetime = $maxlifetime)"); - $epoch = time() - $maxlifetime; + $epoch = common_sql_date(time() - $maxlifetime); - $qry = 'DELETE FROM session ' . - 'WHERE modified < "'.$epoch.'"'; + $ids = array(); $session = new Session(); + $session->whereAdd('modified < "'.$epoch.'"'); + $session->selectAdd(); + $session->selectAdd('id'); - $result = $session->query($qry); + $session->find(); - self::logdeb("garbage collection result = $result"); + while ($session->fetch()) { + $ids[] = $session->id; + } + + $session->free(); + + foreach ($ids as $id) { + self::destroy($id); + } } static function setSaveHandler()