Pre-fill profiles in notice streams
This commit is contained in:
parent
e530a0868d
commit
874f1db389
@ -106,7 +106,7 @@ class Notice extends Memcached_DataObject
|
|||||||
function getProfile()
|
function getProfile()
|
||||||
{
|
{
|
||||||
if (is_int($this->_profile) && $this->_profile == -1) {
|
if (is_int($this->_profile) && $this->_profile == -1) {
|
||||||
$this->_profile = Profile::staticGet('id', $this->profile_id);
|
$this->_setProfile(Profile::staticGet('id', $this->profile_id));
|
||||||
|
|
||||||
if (empty($this->_profile)) {
|
if (empty($this->_profile)) {
|
||||||
// TRANS: Server exception thrown when a user profile for a notice cannot be found.
|
// TRANS: Server exception thrown when a user profile for a notice cannot be found.
|
||||||
@ -117,6 +117,11 @@ class Notice extends Memcached_DataObject
|
|||||||
|
|
||||||
return $this->_profile;
|
return $this->_profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _setProfile($profile)
|
||||||
|
{
|
||||||
|
$this->_profile = $profile;
|
||||||
|
}
|
||||||
|
|
||||||
function delete()
|
function delete()
|
||||||
{
|
{
|
||||||
@ -2492,4 +2497,26 @@ class Notice extends Memcached_DataObject
|
|||||||
return $scope;
|
return $scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function fillProfiles($notices)
|
||||||
|
{
|
||||||
|
$authors = array();
|
||||||
|
|
||||||
|
foreach ($notices as $notice) {
|
||||||
|
if (array_key_exists($notice->profile_id, $authors)) {
|
||||||
|
$authors[$notice->profile_id][] = $notice;
|
||||||
|
} else {
|
||||||
|
$authors[$notice->profile_id] = array($notice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$profile = Profile::multiGet('id', array_keys($authors));
|
||||||
|
|
||||||
|
$profiles = $profile->fetchAll();
|
||||||
|
|
||||||
|
foreach ($profiles as $p) {
|
||||||
|
foreach ($authors[$p->id] as $notice) {
|
||||||
|
$notice->_setProfile($p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,11 @@ class Profile extends Memcached_DataObject
|
|||||||
return Memcached_DataObject::staticGet('Profile',$k,$v);
|
return Memcached_DataObject::staticGet('Profile',$k,$v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function multiGet($keyCol, $keyVals, $skipNulls=true)
|
||||||
|
{
|
||||||
|
return parent::multiGet('Profile', $keyCol, $keyVals, $skipNulls);
|
||||||
|
}
|
||||||
|
|
||||||
/* the code above is auto generated do not remove the tag below */
|
/* the code above is auto generated do not remove the tag below */
|
||||||
###END_AUTOCODE
|
###END_AUTOCODE
|
||||||
|
|
||||||
|
@ -59,6 +59,9 @@ abstract class NoticeStream
|
|||||||
|
|
||||||
static function getStreamByIds($ids)
|
static function getStreamByIds($ids)
|
||||||
{
|
{
|
||||||
return Notice::multiGet('id', $ids);
|
$notices = Notice::multiGet('id', $ids);
|
||||||
|
// Prefill the profiles
|
||||||
|
Notice::fillProfiles($notices->fetchAll());
|
||||||
|
return $notices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user