]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Don't cache user-specific information for Notice atom entries
authorEvan Prodromou <evan@status.net>
Wed, 8 Dec 2010 12:25:55 +0000 (07:25 -0500)
committerEvan Prodromou <evan@status.net>
Wed, 8 Dec 2010 12:25:55 +0000 (07:25 -0500)
classes/Notice.php
lib/activity.php

index d6710c3e272b8eea85ddf7a4c4cfdfcb0c27e755..a067cd3741fa4fb4b8e6fafff99b0f407cc44ad1 100644 (file)
@@ -1234,7 +1234,7 @@ class Notice extends Memcached_DataObject
      * @return Activity activity object representing this Notice.
      */
 
-    function asActivity($cur = null, $source = false)
+    function asActivity()
     {
         $act = self::cacheGet(Cache::codeKey('notice:as-activity:'.$this->id));
 
@@ -1332,68 +1332,37 @@ class Notice extends Memcached_DataObject
            
             $act->context = $ctx;
 
-            $noticeInfoAttr = array('local_id' => $this->id); // local notice ID (useful to clients for ordering)
+            // Source
 
-            $ns = $this->getSource();
+            $atom_feed = $profile->getAtomFeed();
 
-            if (!empty($ns)) {
-                $noticeInfoAttr['source'] =  $ns->code;
-                if (!empty($ns->url)) {
-                    $noticeInfoAttr['source_link'] = $ns->url;
-                    if (!empty($ns->name)) {
-                        $noticeInfoAttr['source'] =  '<a href="'
-                            . htmlspecialchars($ns->url)
-                            . '" rel="nofollow">'
-                            . htmlspecialchars($ns->name)
-                            . '</a>';
-                    }
-                }
-            }
-
-            if (!empty($cur)) {
-                $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false";
-                $cp = $cur->getProfile();
-                $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this->id)) ? "true" : "false";
-            }
-
-            if (!empty($this->repeat_of)) {
-                $noticeInfoAttr['repeat_of'] = $this->repeat_of;
-            }
-
-            $act->extra[] = array('statusnet:notice_info', $noticeInfoAttr, null);
-
-            if ($source) {
-               
-                $atom_feed = $profile->getAtomFeed();
+            if (!empty($atom_feed)) {
 
-                if (!empty($atom_feed)) {
-
-                    $act->source = new ActivitySource();
+                $act->source = new ActivitySource();
                    
-                    // XXX: we should store the actual feed ID
+                // XXX: we should store the actual feed ID
 
-                    $act->source->id = $atom_feed;
+                $act->source->id = $atom_feed;
 
-                    // XXX: we should store the actual feed title
+                // XXX: we should store the actual feed title
 
-                    $act->source->title = $profile->getBestName();
+                $act->source->title = $profile->getBestName();
 
-                    $act->source->links['alternate'] = $profile->profileurl;
-                    $act->source->links['self']      = $atom_feed;
+                $act->source->links['alternate'] = $profile->profileurl;
+                $act->source->links['self']      = $atom_feed;
 
-                    $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
+                $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
                    
-                    $notice = $profile->getCurrentNotice();
+                $notice = $profile->getCurrentNotice();
 
-                    if (!empty($notice)) {
-                        $act->source->updated = self::utcDate($notice->created);
-                    }
+                if (!empty($notice)) {
+                    $act->source->updated = self::utcDate($notice->created);
+                }
 
-                    $user = User::staticGet('id', $profile->id);
+                $user = User::staticGet('id', $profile->id);
 
-                    if (!empty($user)) {
-                        $act->source->links['license'] = common_config('license', 'url');
-                    }
+                if (!empty($user)) {
+                    $act->source->links['license'] = common_config('license', 'url');
                 }
             }
 
@@ -1414,12 +1383,65 @@ class Notice extends Memcached_DataObject
     // This has gotten way too long. Needs to be sliced up into functional bits
     // or ideally exported to a utility class.
 
-    function asAtomEntry($namespace=false, $source=false, $author=true, $cur=null)
+    function asAtomEntry($namespace=false,
+                         $source=false,
+                         $author=true, 
+                         $cur=null)
+    {
+        $act = $this->asActivity();
+        $act->extra[] = $this->noticeInfo($cur);
+        return $act->asString($namespace, $author, $source);
+    }
+
+    /**
+     * Extra notice info for atom entries
+     * 
+     * Clients use some extra notice info in the atom stream.
+     * This gives it to them.
+     *
+     * @param User $cur Current user
+     *
+     * @return array representation of <statusnet:notice_info> element
+     */
+
+    function noticeInfo($cur)
     {
-        $act = $this->asActivity($cur, $source);
-        return $act->asString($namespace, $author);
+        // local notice ID (useful to clients for ordering)
+
+        $noticeInfoAttr = array('local_id' => $this->id);
+
+        // notice source
+
+        $ns = $this->getSource();
+
+        if (!empty($ns)) {
+            $noticeInfoAttr['source'] =  $ns->code;
+            if (!empty($ns->url)) {
+                $noticeInfoAttr['source_link'] = $ns->url;
+                if (!empty($ns->name)) {
+                    $noticeInfoAttr['source'] =  '<a href="'
+                        . htmlspecialchars($ns->url)
+                        . '" rel="nofollow">'
+                        . htmlspecialchars($ns->name)
+                        . '</a>';
+                }
+            }
+        }
+
+        // favorite and repeated
+
+        if (!empty($cur)) {
+            $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false";
+            $cp = $cur->getProfile();
+            $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this->id)) ? "true" : "false";
+        }
+
+        if (!empty($this->repeat_of)) {
+            $noticeInfoAttr['repeat_of'] = $this->repeat_of;
+        }
+
+        return array('statusnet:notice_info', $noticeInfoAttr, null);
     }
-    
 
     /**
      * Returns an XML string fragment with a reference to a notice as an
index d3eeadcee9eb106d095e7e901f892e58a476a338..c3a984a7b994f289995dccf521ee0e4eb8b83fda 100644 (file)
@@ -327,16 +327,8 @@ class Activity
         return null;
     }
 
-    function asString($namespace=false, $author=true)
+    function asString($namespace=false, $author=true, $source=false)
     {
-        $c = Cache::instance();
-
-        $str = $c->get(Cache::codeKey('activity:as-string:'.$this->id));
-
-        if (!empty($str)) {
-            return $str;
-        }
-
         $xs = new XMLStringer(true);
 
         if ($namespace) {
@@ -502,7 +494,7 @@ class Activity
 
         // Info on the source feed
 
-        if (!empty($this->source)) {
+        if ($source && !empty($this->source)) {
             $xs->elementStart('source');
            
             $xs->element('id', null, $this->source->id);
@@ -559,8 +551,6 @@ class Activity
 
         $str = $xs->getString();
        
-        $c->set(Cache::codeKey('activity:as-string:'.$this->id), $str);
-       
         return $str;
     }