From: Mikael Nordfeldth Date: Thu, 5 Jun 2014 22:07:32 +0000 (+0200) Subject: Non-dynamic user and group fetching in Profile X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1217cd59bf0c818af68847e096d19d8fe6c42efc;p=quix0rs-gnu-social.git Non-dynamic user and group fetching in Profile --- diff --git a/classes/Profile.php b/classes/Profile.php index e48092cd83..e4c68724ee 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -92,32 +92,40 @@ class Profile extends Managed_DataObject return $user->getProfile(); } - protected $_user = -1; // Uninitialized value distinct from null + protected $_user = array(); public function getUser() { - if ($this->_user === -1) { - $this->_user = User::getKV('id', $this->id); + if (!isset($this->_user[$this->id])) { + $this->_setUser(User::getKV('id', $this->id)); } - if (!$this->_user instanceof User) { + return $this->_user[$this->id]; + } + + public function _setUser(User $user=null) + { + if (!$user instanceof User) { throw new NoSuchUserException(array('id'=>$this->id)); } - - return $this->_user; + $this->_user[$this->id] = $user; } - protected $_group = -1; + protected $_group = array(); public function getGroup() { - if ($this->_group === -1) { - $this->_group = User_group::getKV('profile_id', $this->id); + if (!isset($this->_group[$this->id])) { + $this->_setGroup(User_group::getKV('profile_id', $this->id)); } - if (!$this->_group instanceof User_group) { + return $this->_group[$this->id]; + } + + public function _setGroup(User_group $group=null) + { + if (!$group instanceof User_group) { throw new NoSuchGroupException(array('profile_id'=>$this->id)); } - - return $this->_group; + $this->_group[$this->id] = $group; } public function isGroup() @@ -140,8 +148,6 @@ class Profile extends Managed_DataObject return true; } - protected $_avatars = array(); - public function getAvatar($width, $height=null) { return Avatar::byProfile($this, $width, $height); @@ -1539,7 +1545,7 @@ class Profile extends Managed_DataObject function __sleep() { $vars = parent::__sleep(); - $skip = array('_user', '_avatars'); + $skip = array('_user', '_group'); return array_diff($vars, $skip); }