return $reply;
}
+ protected $_replies = -1;
+
/**
* Pull the complete list of @-reply targets for this notice.
*
*/
function getReplies()
{
- $keypart = sprintf('notice:reply_ids:%d', $this->id);
-
- $idstr = self::cacheGet($keypart);
+ if ($this->_replies != -1) {
+ return $this->_replies;
+ }
- if ($idstr !== false) {
- $ids = explode(',', $idstr);
- } else {
- $ids = array();
+ $replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', array($this->id));
- $reply = new Reply();
- $reply->selectAdd();
- $reply->selectAdd('profile_id');
- $reply->notice_id = $this->id;
+ $ids = array();
- if ($reply->find()) {
- while($reply->fetch()) {
- $ids[] = $reply->profile_id;
- }
- }
- self::cacheSet($keypart, implode(',', $ids));
+ foreach ($replyMap[$this->id] as $reply) {
+ $ids[] = $reply->profile_id;
}
+ $this->_replies = $ids;
+
return $ids;
}
+ function _setReplies($replies)
+ {
+ $this->_replies = $replies;
+ }
+
/**
* Pull the complete list of @-reply targets for this notice.
*
function __sleep()
{
$vars = parent::__sleep();
- $skip = array('_original', '_profile', '_groups', '_attachments', '_faves');
+ $skip = array('_original', '_profile', '_groups', '_attachments', '_faves', '_replies');
return array_diff($vars, $skip);
}
$notice->_setFaves($faveMap[$notice->id]);
}
}
+
+ static function fillReplies(&$notices)
+ {
+ $ids = self::_idsOf($notices);
+ $replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', $ids);
+ foreach ($notices as $notice) {
+ $replies = $replyMap[$notice->id];
+ $ids = array();
+ foreach ($replies as $reply) {
+ $ids[] = $reply->profile_id;
+ }
+ $notice->_setReplies($ids);
+ }
+ }
}