]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
FilteringNoticeStream now uses OOP for getNotices
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 12 May 2014 09:08:25 +0000 (11:08 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 12 May 2014 09:08:25 +0000 (11:08 +0200)
getNoticeIds gives the notices to fetch, which are caught by getNotices
in a parent class.

lib/filteringnoticestream.php

index 221e9cd70591302d33f4644a0f8012b51a3cfee6..b4ec6687bb7c92831ed30114d0de9847cfdbab45 100644 (file)
@@ -56,7 +56,7 @@ abstract class FilteringNoticeStream extends NoticeStream
 
     abstract function filter($notice);
 
-    function getNotices($offset, $limit, $sinceId=null, $maxId=null)
+    function getNoticeIds($offset, $limit, $since_id, $max_id)
     {
         // "offset" is virtual; we have to get a lot
         $total = $offset + $limit;
@@ -73,22 +73,18 @@ abstract class FilteringNoticeStream extends NoticeStream
         $round = 0;
 
         do {
-
-            $raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId);
+            $raw = $this->upstream->getNotices($startAt, $askFor, $since_id, $max_id);
 
             $results = $raw->N;
-
             if ($results == 0) {
                 break;
             }
 
             $notices = $raw->fetchAll();
-            
             $this->prefill($notices);
-
             foreach ($notices as $notice) {
                 if ($this->filter($notice)) {
-                    $filtered[] = $notice;
+                    $filtered[] = $notice->id;
                     if (count($filtered) >= $total) {
                         break;
                     }
@@ -96,11 +92,8 @@ abstract class FilteringNoticeStream extends NoticeStream
             }
 
             // XXX: make these smarter; factor hit rate into $askFor
-
             $startAt += $askFor;
-            
             $hits = count($filtered);
-
             $lastAsk = $askFor;
 
             if ($hits === 0) {
@@ -110,23 +103,9 @@ abstract class FilteringNoticeStream extends NoticeStream
             }
 
             $round++;
-
         } while (count($filtered) < $total && $results >= $lastAsk);
 
-        return new ArrayWrapper(array_slice($filtered, $offset, $limit));
-    }
-
-    function getNoticeIds($offset, $limit, $sinceId, $maxId)
-    {
-        $notices = $this->getNotices($offset, $limit, $sinceId, $maxId);
-
-        $ids = array();
-
-        while ($notices->fetch()) {
-            $ids[] = $notices->id;
-        }
-
-        return $ids;
+        return array_slice(array_values($filtered), $offset, $limit);
     }
 
     function prefill($notices)