diff options
author | Siebrand Mazeland <s.mazeland@xs4all.nl> | 2010-01-13 23:10:00 +0100 |
---|---|---|
committer | Siebrand Mazeland <s.mazeland@xs4all.nl> | 2010-01-13 23:10:00 +0100 |
commit | 108c51fa6859ec56269078ef9bd0459fdbd9b1ba (patch) | |
tree | c45dc1036d80ba0fdc58473819cde12bcc03eb32 /classes/Notice.php | |
parent | f7f82982ec9a8671195efdc278c2987aa92c083c (diff) | |
parent | 25ed2d2c872e59fd99b54fdf0dec1ca448feca00 (diff) |
Merge branch '0.9.x' of git://gitorious.org/statusnet/mainline into 0.9.x
Diffstat (limited to 'classes/Notice.php')
-rw-r--r-- | classes/Notice.php | 122 |
1 files changed, 93 insertions, 29 deletions
diff --git a/classes/Notice.php b/classes/Notice.php index 9bda47827..a43ce867b 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(); @@ -276,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); } @@ -300,8 +298,6 @@ class Notice extends Memcached_DataObject // XXX: some of these functions write to the DB - $notice->query('BEGIN'); - $id = $notice->insert(); if (!$id) { @@ -339,11 +335,13 @@ class Notice extends Memcached_DataObject $notice->saveTags(); - $notice->addToInboxes(); + $groups = $notice->saveGroups(); - $notice->saveUrls(); + $recipients = $notice->saveReplies(); - $notice->query('COMMIT'); + $notice->addToInboxes($groups, $recipients); + + $notice->saveUrls(); Event::handle('EndNoticeSave', array($notice)); } @@ -503,20 +501,6 @@ class Notice extends Memcached_DataObject $original->free(); 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); } } } @@ -842,11 +826,24 @@ class Notice extends Memcached_DataObject return $ids; } - function addToInboxes() + function whoGets($groups=null, $recipients=null) { - // XXX: loads constants + $c = self::memcache(); - $inbox = new Notice_inbox(); + if (!empty($c)) { + $ni = $c->get(common_cache_key('notice:who_gets:'.$this->id)); + if ($ni !== false) { + return $ni; + } + } + + if (is_null($groups)) { + $groups = $this->getGroups(); + } + + if (is_null($recipients)) { + $recipients = $this->getReplies(); + } $users = $this->getSubscribedUsers(); @@ -860,7 +857,6 @@ class Notice extends Memcached_DataObject $ni[$id] = NOTICE_INBOX_SOURCE_SUB; } - $groups = $this->saveGroups(); $profile = $this->getProfile(); foreach ($groups as $group) { @@ -875,8 +871,6 @@ class Notice extends Memcached_DataObject } } - $recipients = $this->saveReplies(); - foreach ($recipients as $recipient) { if (!array_key_exists($recipient, $ni)) { @@ -887,7 +881,19 @@ class Notice extends Memcached_DataObject } } - Notice_inbox::bulkInsert($this->id, $this->created, $ni); + if (!empty($c)) { + // XXX: pack this data better + $c->set(common_cache_key('notice:who_gets:'.$this->id), $ni); + } + + return $ni; + } + + function addToInboxes($groups, $recipients) + { + $ni = $this->whoGets($groups, $recipients); + + Inbox::bulkInsert($this->id, array_keys($ni)); return; } @@ -921,6 +927,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 */ @@ -991,6 +1003,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)) { @@ -1077,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(); |