]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
More SQL in the conversation notice fetching
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 11 May 2014 20:46:40 +0000 (22:46 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 11 May 2014 20:46:40 +0000 (22:46 +0200)
lib/conversationnoticestream.php

index 1d823760d7cab592b3b4f54f98b4d729f1e3737a..7d2e70354590015304018e8fb35a99f8eee5637c 100644 (file)
@@ -76,35 +76,30 @@ class RawConversationNoticeStream extends NoticeStream
         $this->id = $id;
     }
 
-    function getNotices($offset, $limit, $sinceId = null, $maxId = null)
-    {
-        $all = Notice::listGet('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);
-    }
-
     function getNoticeIds($offset, $limit, $since_id, $max_id)
     {
-        $notice = $this->getNotices($offset, $limit, $since_id, $max_id);
-        $ids = $notice->fetchAll('id');
-        return $ids;
-    }
+        $conv = Conversation::getKV('id', $this->id);
+        if (!$conv instanceof Conversation) {
+            throw new ServerException('Could not find conversation');
+        }
+        $notice = new Notice();
+        // SELECT
+        $notice->selectAdd();
+        $notice->selectAdd('id');
 
-    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;
+        // WHERE
+        $notice->conversation = $this->id;
+        if (!empty($since_id)) {
+            $notice->whereAdd(sprintf('notice.id > %d', $since_id));
         }
+        if (!empty($max_id)) {
+            $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
+        }
+        $notice->limit($offset, $limit);
+
+        // ORDER BY
+        // currently imitates the previously used "_reverseChron" sorting
+        $notice->orderBy('notice.created DESC');
+        return $notice->fetchAll('id');
     }
 }