common_log_db_error($fave, 'INSERT', __FILE__);
return false;
}
- self::blow('fave:by_notice', $fave->notice_id);
+ self::blow('fave:by_notice:%d', $fave->notice_id);
Event::handle('EndFavorNotice', array($profile, $notice));
}
if (Event::handle('StartDisfavorNotice', array($profile, $notice, &$result))) {
$result = parent::delete();
- self::blow('fave:by_notice', $this->notice_id);
+ self::blow('fave:by_notice:%d', $this->notice_id);
if ($result) {
Event::handle('EndDisfavorNotice', array($profile, $notice));
static function byNotice($noticeId)
{
$c = self::memcache();
- $key = Cache::key('fave:by_notice', $noticeId);
+ $key = Cache::key('fave:by_notice:' . $noticeId);
$wrapper = $c->get($key);
if (!$wrapper) {
$fave->notice_id = $noticeId;
$fave->find();
- $profiles = array();
+ $list = array();
while ($fave->fetch()) {
$list[] = clone($fave);
}
}
self::blow('fave:by_notice', $this->id);
+
+ if ($this->conversation) {
+ // In case we're the first, will need to calc a new root.
+ self::blow('notice:conversation_root:%d', $this->conversation);
+ }
}
/** save all urls in the notice to the db
return false;
}
+ /**
+ * Grab the earliest notice from this conversation.
+ *
+ * @return Notice or null
+ */
+ function conversationRoot()
+ {
+ if (!empty($this->conversation)) {
+ $c = self::memcache();
+
+ $key = Cache::key('notice:conversation_root:' . $this->conversation);
+ $notice = $c->get($key);
+ if ($notice) {
+ return $notice;
+ }
+
+ $notice = new Notice();
+ $notice->conversation = $this->conversation;
+ $notice->orderBy('CREATED');
+ $notice->limit(1);
+ $notice->find(true);
+
+ if ($notice->N) {
+ $c->set($key, $notice);
+ return $notice;
+ }
+ }
+ return null;
+ }
/**
* Pull up a full list of local recipients who will be getting
* this notice in their inbox. Results will be cached, so don't
$conversations[$convo] = true;
// Get the convo's root notice
- // @fixme stream goes in wrong direction, this needs sane caching
- //$notice = Notice::conversationStream($convo, 0, 1);
- //$notice->fetch();
- $root = new Notice();
- $root->conversation = $notice->conversation;
- $root->orderBy('CREATED');
- $root->limit(1);
- $root->find(true);
+ $root = $notice->conversationRoot();
+ if ($root) {
+ $notice = $root;
+ }
try {
- $item = $this->newListItem($root);
+ $item = $this->newListItem($notice);
$item->show();
} catch (Exception $e) {
// we log exceptions and continue