From: Evan Prodromou Date: Thu, 7 Apr 2011 20:55:32 +0000 (-0400) Subject: store oft-requested stuff in the data object X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=adf4d960133c262f2e7358546c99b727806cebde;p=quix0rs-gnu-social.git store oft-requested stuff in the data object --- diff --git a/classes/Notice.php b/classes/Notice.php index c80e57dc97..1688443301 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -96,17 +96,21 @@ class Notice extends Memcached_DataObject const GROUP_SCOPE = 4; const FOLLOWER_SCOPE = 8; + protected $_profile = -1; + function getProfile() { - $profile = Profile::staticGet('id', $this->profile_id); + if ($this->_profile == -1) { + $this->_profile = Profile::staticGet('id', $this->profile_id); - if (empty($profile)) { - // TRANS: Server exception thrown when a user profile for a notice cannot be found. - // TRANS: %1$d is a profile ID (number), %2$d is a notice ID (number). - throw new ServerException(sprintf(_('No such profile (%1$d) for notice (%2$d).'), $this->profile_id, $this->id)); + if (empty($this->_profile)) { + // TRANS: Server exception thrown when a user profile for a notice cannot be found. + // TRANS: %1$d is a profile ID (number), %2$d is a notice ID (number). + throw new ServerException(sprintf(_('No such profile (%1$d) for notice (%2$d).'), $this->profile_id, $this->id)); + } } - return $profile; + return $this->_profile; } function delete() diff --git a/classes/Profile.php b/classes/Profile.php index d87ace42c5..b8c4932780 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -52,9 +52,15 @@ class Profile extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + protected $_user = -1; // Uninitialized value distinct from null + function getUser() { - return User::staticGet('id', $this->id); + if ($this->_user == -1) { + $this->_user = User::staticGet('id', $this->id); + } + + return $this->_user; } function getAvatar($width, $height=null) diff --git a/classes/User.php b/classes/User.php index f2b5b08371..48b0f49f3d 100644 --- a/classes/User.php +++ b/classes/User.php @@ -73,16 +73,21 @@ class User extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + protected $_profile = -1; + /** * @return Profile */ function getProfile() { - $profile = Profile::staticGet('id', $this->id); - if (empty($profile)) { - throw new UserNoProfileException($this); + if ($this->_profile == -1) { // invalid but distinct from null + $this->_profile = Profile::staticGet('id', $this->id); + if (empty($this->_profile)) { + throw new UserNoProfileException($this); + } } - return $profile; + + return $this->_profile; } function isSubscribed($other)