common_log_db_error($fave, 'INSERT', __FILE__);
return false;
}
+ self::blow('fave:by_notice', $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', $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();
+
+ $profiles = array();
+ while ($fave->fetch()) {
+ $list[] = clone($fave);
+ }
+ $wrapper = new ArrayWrapper($list);
+ $c->set($key, $wrapper);
+ }
+ return $wrapper;
+ }
}
{
function getProfiles()
{
- // @fixme caching & scalability!
- $fave = new Fave();
- $fave->notice_id = $this->notice->id;
- $fave->find();
-
+ $fave = Fave::byNotice($this->notice->id);
$profiles = array();
while ($fave->fetch()) {
$profiles[] = $fave->user_id;
{
function getProfiles()
{
- // @fixme caching & scalability!
- $rep = new Notice();
- $rep->repeat_of = $this->notice->id;
- $rep->find();
+ $rep = $this->notice->repeatStream();
$profiles = array();
while ($rep->fetch()) {