common_log_db_error($fave, 'INSERT', __FILE__);
return false;
}
- self::blow('fave:by_notice:%d', $fave->notice_id);
+ self::blow('fave:list:notice_id:%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:%d', $this->notice_id);
+ self::blow('fave:list:notice_id:%d', $this->notice_id);
if ($result) {
Event::handle('EndDisfavorNotice', array($profile, $notice));
return $fav;
}
-
- /**
- * Grab a list of profile who have favored this notice.
- *
- * @return ArrayWrapper masquerading as a Fave
- */
- static function byNotice($noticeId)
- {
- $c = self::memcache();
- $key = Cache::key('fave:by_notice:' . $noticeId);
-
- $wrapper = $c->get($key);
- if (!$wrapper) {
- // @fixme caching & scalability!
- $fave = new Fave();
- $fave->notice_id = $noticeId;
- $fave->find();
-
- $list = array();
- while ($fave->fetch()) {
- $list[] = clone($fave);
- }
- $wrapper = new ArrayWrapper($list);
- $c->set($key, $wrapper);
- }
- return $wrapper;
- }
}
}
$gis = Memcached_DataObject::listGet('Group_inbox', 'notice_id', array($this->id));
-
+
+ $ids = array();
+
foreach ($gis[$this->id] as $gi)
{
$ids[] = $gi->group_id;
function __sleep()
{
$vars = parent::__sleep();
- $skip = array('_original', '_profile', '_groups');
+ $skip = array('_original', '_profile', '_groups', '_attachments', '_faves');
return array_diff($vars, $skip);
}
$gis = Memcached_DataObject::listGet('Group_inbox', 'notice_id', $ids);
- common_debug(sprintf("Notice::fillGroups(): got %d results for %d notices", count($gis), count($ids)));
-
+ $gids = array();
+
foreach ($gis as $id => $gi)
{
foreach ($gi as $g)
$notice->_setAttachments($files);
}
}
+
+ protected $_faves = -1;
+
+ /**
+ * All faves of this notice
+ *
+ * @return array Array of Fave objects
+ */
+
+ function getFaves()
+ {
+ if ($this->_faves != -1) {
+ return $this->_faves;
+ }
+ $faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', array($noticeId));
+ $this->_faves = $faveMap[$noticeId];
+ return $this->_faves;
+ }
+
+ function _setFaves($faves)
+ {
+ $this->_faves = $faves;
+ }
+
+ static function fillFaves(&$notices)
+ {
+ $ids = self::_idsOf($notices);
+ $faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', $ids);
+ foreach ($notices as $notice) {
+ $notice->_setFaves($faveMap[$notice->id]);
+ }
+ }
}
{
// Prefill attachments
Notice::fillAttachments($notices);
+ // Prefill attachments
+ Notice::fillFaves($notices);
// Prefill the profiles
$profiles = Notice::fillProfiles($notices);
// Prefill the avatars
{
function getProfiles()
{
- $fave = Fave::byNotice($this->notice->id);
+ $faves = $this->notice->getFaves();
$profiles = array();
- while ($fave->fetch()) {
+ foreach ($faves as $fave) {
$profiles[] = $fave->user_id;
}
return $profiles;