]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
use listGet() for ConversationNoticeStream
authorEvan Prodromou <evan@status.net>
Mon, 22 Aug 2011 16:25:04 +0000 (12:25 -0400)
committerEvan Prodromou <evan@status.net>
Mon, 22 Aug 2011 16:25:04 +0000 (12:25 -0400)
classes/Notice.php
lib/conversationnoticestream.php

index 122c3c6299d2f5825d44d685c0e6ce9b5f6d1daf..3fad9bf029e91a3d4179ca94eb9c552b92e9e64c 100644 (file)
@@ -577,10 +577,7 @@ class Notice extends Memcached_DataObject
             $this->blowStream('public');
         }
 
-        // XXX: Before we were blowing the casche only if the notice id
-        // was not the root of the conversation.  What to do now?
-
-        self::blow('notice:conversation_ids:%d', $this->conversation);
+        self::blow('notice:list-ids:conversation:%s', $this->conversation);
         self::blow('conversation::notice_count:%d', $this->conversation);
 
         if (!empty($this->repeat_of)) {
index adf610ffe7b2841c0d15260cc093b3d0216a573b..c43b5deb24a3bd12d5d26da534a21036bcc17ac3 100644 (file)
@@ -20,7 +20,7 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * @category  Cache
+ * @category  NoticeStream
  * @package   StatusNet
  * @author    Evan Prodromou <evan@status.net>
  * @copyright 2011 StatusNet, Inc.
@@ -52,8 +52,7 @@ class ConversationNoticeStream extends ScopingNoticeStream
             $profile = Profile::current();
         }
 
-        parent::__construct(new CachingNoticeStream(new RawConversationNoticeStream($id),
-                                                    'notice:conversation_ids:'.$id),
+        parent::__construct(new RawConversationNoticeStream($id),
                             $profile);
     }
 }
@@ -77,24 +76,35 @@ class RawConversationNoticeStream extends NoticeStream
         $this->id = $id;
     }
 
-    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    function getNotices($offset, $limit, $sinceId = null, $maxId = null)
     {
-        $notice = new Notice();
-
-        $notice->selectAdd(); // clears it
-        $notice->selectAdd('id');
-
-        $notice->conversation = $this->id;
+        $all = Memcached_DataObject::listGet('Notice', 'conversation', array($this->id));
+        $notices = $all[$this->id];
+        // Re-order in reverse-chron
+        usort($notices, array('RawConversationNoticeStream', '_reverseChron'));
+        // FIXME: handle since and max
+        $wanted = array_slice($notices, $offset, $limit);
+        return new ArrayWrapper($wanted);
+    }
 
-        $notice->orderBy('created DESC, id DESC');
+    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    {
+        $notice = $this->getNotices($offset, $limit, $since_id, $max_id);
+        $ids = $notice->fetchAll('id');
+        return $ids;
+    }
 
-        if (!is_null($offset)) {
-            $notice->limit($offset, $limit);
+    function _reverseChron($a, $b)
+    {
+        $at = strtotime($a->created);
+        $bt = strtotime($b->created);
+        
+        if ($at == $bt) {
+            return 0;
+        } else if ($at > $bt) {
+            return -1;
+        } else {
+            return 1;
         }
-
-        Notice::addWhereSinceId($notice, $since_id);
-        Notice::addWhereMaxId($notice, $max_id);
-
-        return $notice->fetchAll('id');
     }
-}
\ No newline at end of file
+}