diff options
-rw-r--r-- | classes/Memcached_DataObject.php | 32 | ||||
-rw-r--r-- | classes/Notice.php | 2 | ||||
-rw-r--r-- | classes/Notice_inbox.php | 9 | ||||
-rw-r--r-- | scripts/triminboxes.php | 24 |
4 files changed, 35 insertions, 32 deletions
diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index cf7fb4340..b43cb0b56 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -23,20 +23,6 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; class Memcached_DataObject extends DB_DataObject { - /** - * Destructor to free global memory resources associated with - * this data object when it's unset or goes out of scope. - * DB_DataObject doesn't do this yet by itself. - */ - - function __destruct() - { - $this->free(); - if (method_exists('DB_DataObject', '__destruct')) { - parent::__destruct(); - } - } - function &staticGet($cls, $k, $v=null) { if (is_null($v)) { @@ -53,14 +39,14 @@ class Memcached_DataObject extends DB_DataObject } else { $i = DB_DataObject::factory($cls); if (empty($i)) { - return null; + return false; } $result = $i->get($k, $v); if ($result) { $i->encache(); return $i; } else { - return null; + return false; } } } @@ -113,7 +99,7 @@ class Memcached_DataObject extends DB_DataObject } static function cacheKey($cls, $k, $v) { - if (is_object($cls) || is_object($j) || is_object($v)) { + if (is_object($cls) || is_object($k) || is_object($v)) { $e = new Exception(); common_log(LOG_ERR, __METHOD__ . ' object in param: ' . str_replace("\n", " ", $e->getTraceAsString())); @@ -253,18 +239,6 @@ class Memcached_DataObject extends DB_DataObject return new ArrayWrapper($cached); } - function cleanup() - { - global $_DB_DATAOBJECT; - - if (isset($_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid])) { - unset($_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid]); - } - if (isset($_DB_DATAOBJECT['RESULTS'][$this->_DB_resultid])) { - unset($_DB_DATAOBJECT['RESULTS'][$this->_DB_resultid]); - } - } - // We overload so that 'SET NAMES "utf8"' is called for // each connection diff --git a/classes/Notice.php b/classes/Notice.php index 0bb3b861c..93e94230d 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -214,7 +214,7 @@ class Notice extends Memcached_DataObject extract($options); } - if (empty($is_local)) { + if (!isset($is_local)) { $is_local = Notice::LOCAL_PUBLIC; } diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index b39006542..d3ddad656 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -106,6 +106,13 @@ class Notice_inbox extends Memcached_DataObject return Memcached_DataObject::pkeyGet('Notice_inbox', $kv); } + /** + * Trim inbox for a given user to latest NOTICE_INBOX_LIMIT items + * (up to NOTICE_INBOX_GC_MAX will be deleted). + * + * @param int $user_id + * @return int count of notices dropped from the inbox, if any + */ static function gc($user_id) { $entry = new Notice_inbox(); @@ -133,6 +140,8 @@ class Notice_inbox extends Memcached_DataObject $notices = array(); } } + + return $total; } static function deleteMatching($user_id, $notices) diff --git a/scripts/triminboxes.php b/scripts/triminboxes.php index da09817e5..ea4751305 100644 --- a/scripts/triminboxes.php +++ b/scripts/triminboxes.php @@ -21,19 +21,21 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); $shortoptions = 'u::'; -$longoptions = array('start-user-id::'); +$longoptions = array('start-user-id=', 'sleep-time='); $helptext = <<<END_OF_TRIM_HELP Batch script for trimming notice inboxes to a reasonable size. -u <id> --start-user-id=<id> User ID to start after. Default is all. + --sleep-time=<integer> Amount of time to wait (in seconds) between trims. Default is zero. END_OF_TRIM_HELP; require_once INSTALLDIR.'/scripts/commandline.inc'; $id = null; +$sleep_time = 0; if (have_option('u')) { $id = get_option_value('u'); @@ -43,6 +45,12 @@ if (have_option('u')) { $id = null; } +if (have_option('--sleep-time')) { + $sleep_time = intval(get_option_value('--sleep-time')); +} + +$quiet = have_option('q') || have_option('--quiet'); + $user = new User(); if (!empty($id)) { @@ -52,5 +60,17 @@ if (!empty($id)) { $cnt = $user->find(); while ($user->fetch()) { - Notice_inbox::gc($user->id); + if (!$quiet) { + print "Trimming inbox for user $user->id"; + } + $count = Notice_inbox::gc($user->id); + if ($count) { + if (!$quiet) { + print ": $count trimmed..."; + } + sleep($sleep_time); + } + if (!$quiet) { + print "\n"; + } } |