Caching for conversation root lookup, some logic fixes in threaded view

This commit is contained in:
Brion Vibber 2011-03-17 17:36:53 -07:00
parent 0c2c73659c
commit 90a7631592
3 changed files with 43 additions and 13 deletions

View File

@ -44,7 +44,7 @@ class Fave extends Memcached_DataObject
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));
}
@ -62,7 +62,7 @@ class Fave extends Memcached_DataObject
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));
@ -219,7 +219,7 @@ class Fave extends Memcached_DataObject
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) {
@ -228,7 +228,7 @@ class Fave extends Memcached_DataObject
$fave->notice_id = $noticeId;
$fave->find();
$profiles = array();
$list = array();
while ($fave->fetch()) {
$list[] = clone($fave);
}

View File

@ -498,6 +498,11 @@ class Notice extends Memcached_DataObject
}
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
@ -776,6 +781,35 @@ class Notice extends Memcached_DataObject
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

View File

@ -91,17 +91,13 @@ class ThreadedNoticeList extends NoticeList
$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