/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ static function pivotGet($keyCol, $keyVals, $otherCols)
+ {
+ return Memcached_DataObject::pivotGet('Avatar', $keyCol, $keyVals, $otherCols);
+ }
+
// We clean up the file, too
function delete()
static function fillProfiles($notices)
{
- $authors = array();
+ $map = self::getProfiles($notices);
foreach ($notices as $notice) {
- if (array_key_exists($notice->profile_id, $authors)) {
- $authors[$notice->profile_id][] = $notice;
- } else {
- $authors[$notice->profile_id] = array($notice);
- }
+ if (array_key_exists($notice->profile_id, $map)) {
+ $notice->_setProfile($map[$notice->profile_id]);
+ }
}
- $profile = Profile::multiGet('id', array_keys($authors));
+ return array_values($map);
+ }
+
+ static function getProfiles(&$notices)
+ {
+ $ids = array();
+ foreach ($notices as $notice) {
+ $ids[] = $notice->profile_id;
+ }
- $profiles = $profile->fetchAll();
+ $ids = array_unique($ids);
- foreach ($profiles as $p) {
- foreach ($authors[$p->id] as $notice) {
- $notice->_setProfile($p);
- }
- }
+ return Memcached_DataObject::pivotGet('Profile', 'id', $ids);
}
}
return $this->_user;
}
+ protected $_avatars = array();
+
function getAvatar($width, $height=null)
{
if (is_null($height)) {
$height = $width;
}
+ if (array_key_exists($width, $this->_avatars)) {
+ return $this->_avatars[$width];
+ }
+
$avatar = null;
if (Event::handle('StartProfileGetAvatar', array($this, $width, &$avatar))) {
Event::handle('EndProfileGetAvatar', array($this, $width, &$avatar));
}
+ $this->_avatars[$width] = $avatar;
+
return $avatar;
}
+ function _fillAvatar($width, $avatar)
+ {
+ $this->_avatars[$width] = $avatar;
+ }
+
function getOriginalAvatar()
{
$avatar = DB_DataObject::factory('avatar');
function __sleep()
{
$vars = parent::__sleep();
- $skip = array('_user');
+ $skip = array('_user', '_avatars');
return array_diff($vars, $skip);
}
+
+ static function fillAvatars(&$profiles, $width)
+ {
+ $ids = array();
+ foreach ($profiles as $profile) {
+ $ids[] = $profile->id;
+ }
+
+ common_debug('Got here');
+
+ $avatars = Avatar::pivotGet('profile_id', $ids, array('width' => $width,
+ 'height' => $width));
+
+ common_debug(sprintf('Got %d avatars for %d profiles', count($avatars), count($ids)));
+
+ foreach ($profiles as $profile) {
+ $profile->_fillAvatar($width, $avatars[$profile->id]);
+ }
+ }
}
function prefill(&$notices)
{
// Prefill the profiles
- Notice::fillProfiles($notices);
+ $profiles = Notice::fillProfiles($notices);
+ Profile::fillAvatars($profiles, AVATAR_STREAM_SIZE);
}
}
function prefill(&$notices)
{
// Prefill the profiles
- Notice::fillProfiles($notices);
+ $profiles = Notice::fillProfiles($notices);
+ Profile::fillAvatars($profiles, AVATAR_MINI_SIZE);
}
}