]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge remote-tracking branch 'gitorious/1.0.x' into 1.0.x
authorEvan Prodromou <evan@status.net>
Fri, 8 Apr 2011 20:14:09 +0000 (16:14 -0400)
committerEvan Prodromou <evan@status.net>
Fri, 8 Apr 2011 20:14:09 +0000 (16:14 -0400)
classes/Notice.php
classes/Profile.php
classes/User.php
plugins/Event/EventPlugin.php

index c80e57dc9759d1b3846e2d5cf139a6816c634cff..168844330193f537b4f6d8d7c5d1b1979388e365 100644 (file)
@@ -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()
index d87ace42c5a77760574699f680850f0746a3efdd..2c1582628242b959f818aba15251104d81ea716c 100644 (file)
@@ -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)
@@ -465,34 +471,6 @@ class Profile extends Memcached_DataObject
 
     function hasFave($notice)
     {
-        $cache = Cache::instance();
-
-        // XXX: Kind of a hack.
-
-        if (!empty($cache)) {
-            // This is the stream of favorite notices, in rev chron
-            // order. This forces it into cache.
-
-            $ids = Fave::idStream($this->id, 0, CachingNoticeStream::CACHE_WINDOW);
-
-            // If it's in the list, then it's a fave
-
-            if (in_array($notice->id, $ids)) {
-                return true;
-            }
-
-            // If we're not past the end of the cache window,
-            // then the cache has all available faves, so this one
-            // is not a fave.
-
-            if (count($ids) < CachingNoticeStream::CACHE_WINDOW) {
-                return false;
-            }
-
-            // Otherwise, cache doesn't have all faves;
-            // fall through to the default
-        }
-
         $fave = Fave::pkeyGet(array('user_id' => $this->id,
                                     'notice_id' => $notice->id));
         return ((is_null($fave)) ? false : true);
index f2b5b083718dbaa556c67ccd3b5e21a787df270b..48b0f49f3da93e9802031e8ef5f39cf6c8a369fe 100644 (file)
@@ -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)
index 63d92e63c7bc2175c3fbb0ac9764fb064c09ee19..aca2922f177e324e574aaf4299c2c52890da2e05 100644 (file)
@@ -329,6 +329,11 @@ class EventPlugin extends MicroappPlugin
     {
         $rsvp = RSVP::fromNotice($notice);
 
+        if (empty($rsvp)) {
+            $out->element('p', null, _('Deleted.'));
+            return;
+        }
+
         $out->elementStart('div', 'rsvp');
         $out->raw($rsvp->asHTML());
         $out->elementEnd('div');
@@ -340,8 +345,10 @@ class EventPlugin extends MicroappPlugin
         $profile = $notice->getProfile();
         $event   = Happening::fromNotice($notice);
 
-        assert(!empty($event));
-        assert(!empty($profile));
+        if (empty($event)) {
+            $out->element('p', null, _('Deleted.'));
+            return;
+        }
 
         $out->elementStart('div', 'vevent event'); // VEVENT IN