pre-fill repeats of notices

This commit is contained in:
Evan Prodromou 2011-08-22 12:39:37 -04:00
parent d3399e93e8
commit 2f1751568a
3 changed files with 42 additions and 9 deletions

View File

@ -581,7 +581,9 @@ class Notice extends Memcached_DataObject
self::blow('conversation::notice_count:%d', $this->conversation);
if (!empty($this->repeat_of)) {
// XXX: we should probably only use one of these
$this->blowStream('notice:repeats:%d', $this->repeat_of);
self::blow('notice:list-ids:repeat_of:%d', $this->repeat_of);
}
$original = Notice::staticGet('id', $this->repeat_of);
@ -2432,7 +2434,7 @@ class Notice extends Memcached_DataObject
function __sleep()
{
$vars = parent::__sleep();
$skip = array('_original', '_profile', '_groups', '_attachments', '_faves', '_replies');
$skip = array('_original', '_profile', '_groups', '_attachments', '_faves', '_replies', '_repeats');
return array_diff($vars, $skip);
}
@ -2597,4 +2599,30 @@ class Notice extends Memcached_DataObject
$notice->_setReplies($ids);
}
}
protected $_repeats;
function getRepeats()
{
if (isset($this->_repeats) && is_array($this->_repeats)) {
return $this->_repeats;
}
$repeatMap = Memcached_DataObject::listGet('Notice', 'repeat_of', array($this->id));
$this->_repeats = $repeatMap[$this->id];
return $this->_repeats;
}
function _setRepeats(&$repeats)
{
$this->_repeats = $repeats;
}
static function fillRepeats(&$notices)
{
$ids = self::_idsOf($notices);
$repeatMap = Memcached_DataObject::listGet('Notice', 'repeat_of', $ids);
foreach ($notices as $notice) {
$notice->_setRepeats($repeatMap[$notice->id]);
}
}
}

View File

@ -128,6 +128,8 @@ class NoticeList extends Widget
Notice::fillAttachments($notices);
// Prefill attachments
Notice::fillFaves($notices);
// Prefill repeat data
Notice::fillRepeats($notices);
// Prefill the profiles
$profiles = Notice::fillProfiles($notices);
// Prefill the avatars
@ -135,13 +137,14 @@ class NoticeList extends Widget
$p = Profile::current();
$ids = array();
foreach ($notices as $notice) {
$ids[] = $notice->id;
}
if (!empty($p)) {
$ids = array();
foreach ($notices as $notice) {
$ids[] = $notice->id;
}
Memcached_DataObject::pivotGet('Fave', 'notice_id', $ids, array('user_id' => $p->id));
Memcached_DataObject::pivotGet('Notice', 'repeat_of', $ids, array('profile_id' => $p->id));
}

View File

@ -559,12 +559,14 @@ class ThreadedNoticeListRepeatsItem extends NoticeListActorsItem
{
function getProfiles()
{
$rep = $this->notice->repeatStream();
$repeats = $this->notice->getRepeats();
$profiles = array();
while ($rep->fetch()) {
foreach ($repeats as $rep) {
$profiles[] = $rep->profile_id;
}
return $profiles;
}