]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
pre-fill the addressees of notices in a list
authorEvan Prodromou <evan@status.net>
Wed, 3 Aug 2011 04:59:09 +0000 (00:59 -0400)
committerEvan Prodromou <evan@status.net>
Wed, 3 Aug 2011 04:59:09 +0000 (00:59 -0400)
classes/Notice.php
lib/filteringnoticestream.php

index eee6c2a5021d3547f32f663d65854b5a93a551cd..d39aea6c225776d398e2e82b1eff7022a49fc10b 100644 (file)
@@ -1303,6 +1303,8 @@ class Notice extends Memcached_DataObject
         return $reply;
     }
 
+    protected $_replies = -1;
+
     /**
      * Pull the complete list of @-reply targets for this notice.
      *
@@ -1310,31 +1312,28 @@ class Notice extends Memcached_DataObject
      */
     function getReplies()
     {
-        $keypart = sprintf('notice:reply_ids:%d', $this->id);
-
-        $idstr = self::cacheGet($keypart);
+        if ($this->_replies != -1) {
+            return $this->_replies;
+        }
 
-        if ($idstr !== false) {
-            $ids = explode(',', $idstr);
-        } else {
-            $ids = array();
+        $replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', array($this->id));
 
-            $reply = new Reply();
-            $reply->selectAdd();
-            $reply->selectAdd('profile_id');
-            $reply->notice_id = $this->id;
+        $ids = array();
 
-            if ($reply->find()) {
-                while($reply->fetch()) {
-                    $ids[] = $reply->profile_id;
-                }
-            }
-            self::cacheSet($keypart, implode(',', $ids));
+        foreach ($replyMap[$this->id] as $reply) {
+            $ids[] = $reply->profile_id;
         }
 
+        $this->_replies = $ids;
+
         return $ids;
     }
 
+    function _setReplies($replies)
+    {
+        $this->_replies = $replies;
+    }
+
     /**
      * Pull the complete list of @-reply targets for this notice.
      *
@@ -2436,7 +2435,7 @@ class Notice extends Memcached_DataObject
     function __sleep()
     {
         $vars = parent::__sleep();
-        $skip = array('_original', '_profile', '_groups', '_attachments', '_faves');
+        $skip = array('_original', '_profile', '_groups', '_attachments', '_faves', '_replies');
         return array_diff($vars, $skip);
     }
     
@@ -2579,4 +2578,18 @@ class Notice extends Memcached_DataObject
             $notice->_setFaves($faveMap[$notice->id]);
         }
     }
+
+    static function fillReplies(&$notices)
+    {
+        $ids = self::_idsOf($notices);
+        $replyMap = Memcached_DataObject::listGet('Reply', 'notice_id', $ids);
+        foreach ($notices as $notice) {
+            $replies = $replyMap[$notice->id];
+            $ids = array();
+            foreach ($replies as $reply) {
+                $ids[] = $reply->profile_id;
+            }
+            $notice->_setReplies($ids);
+        }
+    }
 }
index 267955dfd95ba134930bac405dc1e12e07ca29d3..0b0fab481eb37393a1e336bab9ada36d7e65b63a 100644 (file)
@@ -86,6 +86,7 @@ abstract class FilteringNoticeStream extends NoticeStream
                        // XXX: this should probably only be in the scoping one.
                        
                        Notice::fillGroups($notices);
+                       Notice::fillReplies($notices);
                        
                        foreach ($notices as $notice) {
                 if ($this->filter($notice)) {