Pass correct notice id to Memcached_DataObject::listGet() in getFaves()

This commit is contained in:
Evan Prodromou 2011-08-08 12:01:39 -04:00
parent f405ffa507
commit ac268773bf

View File

@ -2547,7 +2547,7 @@ class Notice extends Memcached_DataObject
} }
} }
protected $_faves = -1; protected $_faves;
/** /**
* All faves of this notice * All faves of this notice
@ -2557,15 +2557,15 @@ class Notice extends Memcached_DataObject
function getFaves() function getFaves()
{ {
if ($this->_faves != -1) { if (isset($this->_faves) && is_array($this->_faves)) {
return $this->_faves; return $this->_faves;
} }
$faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', array($noticeId)); $faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', array($this->id));
$this->_faves = $faveMap[$noticeId]; $this->_faves = $faveMap[$this->id];
return $this->_faves; return $this->_faves;
} }
function _setFaves($faves) function _setFaves(&$faves)
{ {
$this->_faves = $faves; $this->_faves = $faves;
} }
@ -2574,6 +2574,14 @@ class Notice extends Memcached_DataObject
{ {
$ids = self::_idsOf($notices); $ids = self::_idsOf($notices);
$faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', $ids); $faveMap = Memcached_DataObject::listGet('Fave', 'notice_id', $ids);
$cnt = 0;
$faved = array();
foreach ($faveMap as $id => $faves) {
$cnt += count($faves);
if (count($faves) > 0) {
$faved[] = $id;
}
}
foreach ($notices as $notice) { foreach ($notices as $notice) {
$notice->_setFaves($faveMap[$notice->id]); $notice->_setFaves($faveMap[$notice->id]);
} }