From f2a403589cc8858ec3d3ce70f09709f36277c348 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 30 Dec 2009 09:06:07 -1000 Subject: Use inbox instead of notice_inbox --- classes/Notice.php | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 9bda47827..8783912e8 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -125,8 +125,7 @@ class Notice extends Memcached_DataObject 'Fave', 'Notice_tag', 'Group_inbox', - 'Queue_item', - 'Notice_inbox'); + 'Queue_item'); foreach ($related as $cls) { $inst = new $cls(); @@ -504,17 +503,6 @@ class Notice extends Memcached_DataObject unset($original); } - $ni = new Notice_inbox(); - - $ni->notice_id = $this->id; - - if ($ni->find()) { - while ($ni->fetch()) { - $tmk = common_cache_key('user:repeated_to_me:'.$ni->user_id); - $cache->delete($tmk); - } - } - $ni->free(); unset($ni); } @@ -844,10 +832,6 @@ class Notice extends Memcached_DataObject function addToInboxes() { - // XXX: loads constants - - $inbox = new Notice_inbox(); - $users = $this->getSubscribedUsers(); // FIXME: kind of ignoring 'transitional'... @@ -887,7 +871,7 @@ class Notice extends Memcached_DataObject } } - Notice_inbox::bulkInsert($this->id, $this->created, $ni); + Inbox::bulkInsert($this->id, array_keys($ni)); return; } -- cgit v1.2.3-54-g00ecf From 96e51dad4b9ff2208cfef2e578e4bc85a8937680 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 9 Jan 2010 13:55:54 -0800 Subject: whoGets() method for Notice --- classes/Notice.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 8783912e8..6284b8ca5 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -830,7 +830,7 @@ class Notice extends Memcached_DataObject return $ids; } - function addToInboxes() + function whoGets() { $users = $this->getSubscribedUsers(); @@ -871,6 +871,13 @@ class Notice extends Memcached_DataObject } } + return $ni; + } + + function addToInboxes() + { + $ni = $this->whoGets(); + Inbox::bulkInsert($this->id, array_keys($ni)); return; -- cgit v1.2.3-54-g00ecf From fb0d837ddc572993f8c6d1db3de2c96d70101841 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 12 Jan 2010 23:41:33 -0800 Subject: remove transaction for Notice save; causes deadlocks --- classes/Notice.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 6284b8ca5..306956422 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -299,8 +299,6 @@ class Notice extends Memcached_DataObject // XXX: some of these functions write to the DB - $notice->query('BEGIN'); - $id = $notice->insert(); if (!$id) { @@ -342,8 +340,6 @@ class Notice extends Memcached_DataObject $notice->saveUrls(); - $notice->query('COMMIT'); - Event::handle('EndNoticeSave', array($notice)); } -- cgit v1.2.3-54-g00ecf From 3d579fc58007ccb20657bc3959aad220e72e8f30 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 00:16:54 -0800 Subject: memoize Notice::whoGets() --- classes/Notice.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 306956422..c8edc98e1 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -828,6 +828,15 @@ class Notice extends Memcached_DataObject function whoGets() { + $c = self::memcache(); + + if (!empty($c)) { + $ni = $c->get(common_cache_key('notice:who_gets:'.$this->id)); + if ($ni !== false) { + return $ni; + } + } + $users = $this->getSubscribedUsers(); // FIXME: kind of ignoring 'transitional'... @@ -867,6 +876,11 @@ class Notice extends Memcached_DataObject } } + if (!empty($c)) { + // XXX: pack this data better + $c->set(common_cache_key('notice:who_gets:'.$this->id), $ni); + } + return $ni; } -- cgit v1.2.3-54-g00ecf From 5397249e505b6e82c814c2a7ce5bc1bfaad2adf3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 00:45:12 -0800 Subject: remove vestiges of Notice_inbox from cache clearing code in Notice --- classes/Notice.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index c8edc98e1..d651ef80e 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -498,9 +498,6 @@ class Notice extends Memcached_DataObject $original->free(); unset($original); } - - $ni->free(); - unset($ni); } } } -- cgit v1.2.3-54-g00ecf From 8bfa7fdeaf85091907e5c0c9f181655a9a5dcdf5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 00:47:12 -0800 Subject: repeats don't get posted to groups --- classes/Notice.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index d651ef80e..f48e77c1d 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -919,6 +919,12 @@ class Notice extends Memcached_DataObject function saveGroups() { + // Don't save groups for repeats + + if (!empty($this->repeat_of)) { + return array(); + } + $groups = array(); /* extract all !group */ -- cgit v1.2.3-54-g00ecf From 43ff54218934663910f11762ee2a1c1083b119c7 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 01:13:06 -0800 Subject: Don't save reply info for repeats --- classes/Notice.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index f48e77c1d..02cd20391 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -275,7 +275,6 @@ class Notice extends Memcached_DataObject if (isset($repeat_of)) { $notice->repeat_of = $repeat_of; - $notice->reply_to = $repeat_of; } else { $notice->reply_to = self::getReplyTo($reply_to, $profile_id, $source, $final); } @@ -995,6 +994,12 @@ class Notice extends Memcached_DataObject */ function saveReplies() { + // Don't save reply data for repeats + + if (!empty($this->repeat_of)) { + return array(); + } + // Alternative reply format $tname = false; if (preg_match('/^T ([A-Z0-9]{1,64}) /', $this->content, $match)) { -- cgit v1.2.3-54-g00ecf From d032fc038a32c142a6156b1b33ecd6e09ab4764c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 12:37:01 -0800 Subject: make sure whoGets() doesn't write anything --- classes/Notice.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 7 deletions(-) (limited to 'classes/Notice.php') diff --git a/classes/Notice.php b/classes/Notice.php index 02cd20391..a43ce867b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -335,7 +335,11 @@ class Notice extends Memcached_DataObject $notice->saveTags(); - $notice->addToInboxes(); + $groups = $notice->saveGroups(); + + $recipients = $notice->saveReplies(); + + $notice->addToInboxes($groups, $recipients); $notice->saveUrls(); @@ -822,7 +826,7 @@ class Notice extends Memcached_DataObject return $ids; } - function whoGets() + function whoGets($groups=null, $recipients=null) { $c = self::memcache(); @@ -833,6 +837,14 @@ class Notice extends Memcached_DataObject } } + if (is_null($groups)) { + $groups = $this->getGroups(); + } + + if (is_null($recipients)) { + $recipients = $this->getReplies(); + } + $users = $this->getSubscribedUsers(); // FIXME: kind of ignoring 'transitional'... @@ -845,7 +857,6 @@ class Notice extends Memcached_DataObject $ni[$id] = NOTICE_INBOX_SOURCE_SUB; } - $groups = $this->saveGroups(); $profile = $this->getProfile(); foreach ($groups as $group) { @@ -860,8 +871,6 @@ class Notice extends Memcached_DataObject } } - $recipients = $this->saveReplies(); - foreach ($recipients as $recipient) { if (!array_key_exists($recipient, $ni)) { @@ -880,9 +889,9 @@ class Notice extends Memcached_DataObject return $ni; } - function addToInboxes() + function addToInboxes($groups, $recipients) { - $ni = $this->whoGets(); + $ni = $this->whoGets($groups, $recipients); Inbox::bulkInsert($this->id, array_keys($ni)); @@ -1086,6 +1095,52 @@ class Notice extends Memcached_DataObject return $recipientIds; } + function getReplies() + { + // XXX: cache me + + $ids = array(); + + $reply = new Reply(); + $reply->selectAdd(); + $reply->selectAdd('profile_id'); + $reply->notice_id = $this->id; + + if ($reply->find()) { + while($reply->fetch()) { + $ids[] = $reply->profile_id; + } + } + + $reply->free(); + + return $ids; + } + + function getGroups() + { + // XXX: cache me + + $ids = array(); + + $gi = new Group_inbox(); + + $gi->selectAdd(); + $gi->selectAdd('group_id'); + + $gi->notice_id = $this->id; + + if ($gi->find()) { + while ($gi->fetch()) { + $ids[] = $gi->group_id; + } + } + + $gi->free(); + + return $ids; + } + function asAtomEntry($namespace=false, $source=false) { $profile = $this->getProfile(); -- cgit v1.2.3-54-g00ecf