]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Update/add translator documentation.
[quix0rs-gnu-social.git] / classes / Notice.php
index df2ab96d058bde509dd7ada850cab8f6e200cf6e..d18ac2e536eb860a4c1f765ca63b5d32c67b3ed8 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 (is_int($this->_profile) && $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()
@@ -204,7 +208,7 @@ class Notice extends Memcached_DataObject
 
         if (!$id) {
             // TRANS: Server exception. %s are the error details.
-            throw new ServerException(sprintf(_('Database error inserting hashtag: %s'),
+            throw new ServerException(sprintf(_('Database error inserting hashtag: %s.'),
                                               $last_error->message));
             return;
         }
@@ -1186,6 +1190,7 @@ class Notice extends Memcached_DataObject
             $result = $ptagi->insert();
             if (!$result) {
                 common_log_db_error($ptagi, 'INSERT', __FILE__);
+                // TRANS: Server exception thrown when saving profile_tag inbox fails.
                 throw new ServerException(_('Problem saving profile_tag inbox.'));
             }
 
@@ -2285,7 +2290,7 @@ class Notice extends Memcached_DataObject
     /**
      * Check that the given profile is allowed to read, respond to, or otherwise
      * act on this notice.
-     * 
+     *
      * The $scope member is a bitmask of scopes, representing a logical AND of the
      * scope requirement. So, 0x03 (Notice::ADDRESSEE_SCOPE | Notice::SITE_SCOPE) means
      * "only visible to people who are mentioned in the notice AND are users on this site."
@@ -2297,6 +2302,21 @@ class Notice extends Memcached_DataObject
      * @return boolean whether the profile is in the notice's scope
      */
     function inScope($profile)
+    {
+        $keypart = sprintf('notice:in-scope-for:%d:%d', $this->id, $profile->id);
+
+        $result = self::cacheGet($keypart);
+
+        if ($result === false) {
+            $bResult = $this->_inScope($profile);
+            $result = ($bResult) ? 1 : 0;
+            self::cacheSet($keypart, $result, 0, 300);
+        }
+
+        return ($result == 1) ? true : false;
+    }
+
+    protected function _inScope($profile)
     {
         // If there's no scope, anyone (even anon) is in scope.