From 45c9d3d729a9c811282bdb9caa70450218200e8b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 29 Dec 2009 14:05:43 -0800 Subject: [PATCH 1/9] Add progress output and optional --sleep-time parameter to triminboxes.php --- classes/Notice_inbox.php | 9 +++++++++ scripts/triminboxes.php | 24 ++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index b39006542c..d3ddad656a 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 da09817e5b..ea47513051 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 = << --start-user-id= User ID to start after. Default is all. + --sleep-time= 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"; + } } From 45dc24689df85b63eaa13173cd9a111b4a5cf237 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 30 Dec 2009 15:09:24 -0800 Subject: [PATCH 2/9] temp debug logging hack for subscriber list early cutoff bug - we can see a cut off list at http://identi.ca/petercook/subscribers but haven't been able to explain it. will log a little data on the execution through the list --- lib/profilelist.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/profilelist.php b/lib/profilelist.php index 3412d41d1c..ae875ac011 100644 --- a/lib/profilelist.php +++ b/lib/profilelist.php @@ -86,16 +86,21 @@ class ProfileList extends Widget function showProfiles() { + $log = strtolower(get_class($this)) == 'subscriberslist' && $this->owner->nickname == 'petercook'; $cnt = 0; + if ($log) common_log(LOG_INFO, "subbug: starting with {$this->profile->N}"); while ($this->profile->fetch()) { $cnt++; if($cnt > PROFILES_PER_PAGE) { + if ($log) common_log(LOG_INFO, "subbug: breaking at $cnt"); break; } + if ($log) common_log(LOG_INFO, "subbug: showing at $cnt"); $pli = $this->newListItem($this->profile); $pli->show(); } + if ($log) common_log(LOG_INFO, "subbug: ended at $cnt"); return $cnt; } From 9218cce3cdc824e2011bcdf250a08ca1698f5ea1 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 30 Dec 2009 15:55:15 -0800 Subject: [PATCH 3/9] subbug debug info to check on free ordering --- classes/Memcached_DataObject.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index d8b0db5a69..4efec06abe 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -31,11 +31,20 @@ class Memcached_DataObject extends DB_DataObject function __destruct() { + if (get_class($this) == 'Profile') + common_log(LOG_INFO, 'subbug: destructing result id ' . $this->_DB_resultid); $this->free(); if (method_exists('DB_DataObject', '__destruct')) { parent::__destruct(); } } + + function free() + { + if (get_class($this) == 'Profile') + common_log(LOG_INFO, 'subbug: freeing result id ' . $this->_DB_resultid); + parent::free(); + } function &staticGet($cls, $k, $v=null) { From ff50c2b91d9fadaa9a4ede11785408408fc2d3c5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 30 Dec 2009 16:40:59 -0800 Subject: [PATCH 4/9] Revert debugging code --- classes/Memcached_DataObject.php | 9 --------- lib/profilelist.php | 5 ----- 2 files changed, 14 deletions(-) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 4efec06abe..d8b0db5a69 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -31,20 +31,11 @@ class Memcached_DataObject extends DB_DataObject function __destruct() { - if (get_class($this) == 'Profile') - common_log(LOG_INFO, 'subbug: destructing result id ' . $this->_DB_resultid); $this->free(); if (method_exists('DB_DataObject', '__destruct')) { parent::__destruct(); } } - - function free() - { - if (get_class($this) == 'Profile') - common_log(LOG_INFO, 'subbug: freeing result id ' . $this->_DB_resultid); - parent::free(); - } function &staticGet($cls, $k, $v=null) { diff --git a/lib/profilelist.php b/lib/profilelist.php index ae875ac011..3412d41d1c 100644 --- a/lib/profilelist.php +++ b/lib/profilelist.php @@ -86,21 +86,16 @@ class ProfileList extends Widget function showProfiles() { - $log = strtolower(get_class($this)) == 'subscriberslist' && $this->owner->nickname == 'petercook'; $cnt = 0; - if ($log) common_log(LOG_INFO, "subbug: starting with {$this->profile->N}"); while ($this->profile->fetch()) { $cnt++; if($cnt > PROFILES_PER_PAGE) { - if ($log) common_log(LOG_INFO, "subbug: breaking at $cnt"); break; } - if ($log) common_log(LOG_INFO, "subbug: showing at $cnt"); $pli = $this->newListItem($this->profile); $pli->show(); } - if ($log) common_log(LOG_INFO, "subbug: ended at $cnt"); return $cnt; } From 89cca01259d71f3da961ef64def3647f86a01567 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 30 Dec 2009 16:42:57 -0800 Subject: [PATCH 5/9] Take Memcached_DataObject destructor back out to check whether it might be causing some under-the-hood problems. --- classes/Memcached_DataObject.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index d8b0db5a69..644b84d5cf 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)) { From 79c2e3f7202aa652414df885bd4c917a316ea7f3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 1 Jan 2010 11:27:13 -1000 Subject: [PATCH 6/9] Revert "add cleanup method to cleanup a single row" This reverts commit b0527801d9c2b84408bbfdf82bbdc5b778f72cfc. --- classes/Memcached_DataObject.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index cf7fb4340a..f511335083 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -253,18 +253,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 From 52fbd101629b59f279195d0b11c7775b8aa4637f Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 2 Jan 2010 08:36:47 -1000 Subject: [PATCH 7/9] incorrectly used empty() instead of isset() for a variable that could be 0 --- classes/Notice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Notice.php b/classes/Notice.php index 0bb3b861c7..93e94230d9 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; } From 2bd32dfad73d1387353199e5f45d02a9c5d770e5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 2 Jan 2010 16:21:19 -1000 Subject: [PATCH 8/9] change harmless check of to check of in Memcached_DataObject --- classes/Memcached_DataObject.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index bf61b07664..ad8876ff9d 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -99,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())); From d32fb7c7c40e3d5fa67496d5df0574fc9c2e0151 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 2 Jan 2010 16:28:46 -1000 Subject: [PATCH 9/9] return false from Memcached_DataObject::staticGet() on not found, like DB_DataObject --- classes/Memcached_DataObject.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index ad8876ff9d..b43cb0b56f 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -39,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; } } }