From 2f1751568abde87de674ffab7e278612ad26d3ee Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 22 Aug 2011 12:39:37 -0400 Subject: [PATCH] pre-fill repeats of notices --- classes/Notice.php | 30 +++++++++++++++++++++++++++++- lib/noticelist.php | 13 ++++++++----- lib/threadednoticelist.php | 6 ++++-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 3fad9bf029..3ea7a2d497 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -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]); + } + } } diff --git a/lib/noticelist.php b/lib/noticelist.php index 7ec5be1c0f..91acbb8d58 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -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(); + if (!empty($p)) { + + $ids = array(); - foreach ($notices as $notice) { - $ids[] = $notice->id; - } + foreach ($notices as $notice) { + $ids[] = $notice->id; + } - if (!empty($p)) { Memcached_DataObject::pivotGet('Fave', 'notice_id', $ids, array('user_id' => $p->id)); Memcached_DataObject::pivotGet('Notice', 'repeat_of', $ids, array('profile_id' => $p->id)); } diff --git a/lib/threadednoticelist.php b/lib/threadednoticelist.php index 6df4ed99df..88d7bb5b45 100644 --- a/lib/threadednoticelist.php +++ b/lib/threadednoticelist.php @@ -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; } -- 2.39.5