]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/filteringnoticestream.php
Remove filtering notice stream debug comments
[quix0rs-gnu-social.git] / lib / filteringnoticestream.php
index a3bdc08af697746be4c663a78b99d89896a6252a..221e9cd70591302d33f4644a0f8012b51a3cfee6 100644 (file)
@@ -56,7 +56,7 @@ abstract class FilteringNoticeStream extends NoticeStream
 
     abstract function filter($notice);
 
-    function getNotices($offset, $limit, $sinceId, $maxId)
+    function getNotices($offset, $limit, $sinceId=null, $maxId=null)
     {
         // "offset" is virtual; we have to get a lot
         $total = $offset + $limit;
@@ -70,6 +70,7 @@ abstract class FilteringNoticeStream extends NoticeStream
         // or we get nothing from upstream.
 
         $results = null;
+        $round = 0;
 
         do {
 
@@ -81,10 +82,14 @@ abstract class FilteringNoticeStream extends NoticeStream
                 break;
             }
 
-            while ($raw->fetch()) {
-                if ($this->filter($raw)) {
-                    $filtered[] = clone($raw);
-                    if (count($filtered >= $total)) {
+            $notices = $raw->fetchAll();
+            
+            $this->prefill($notices);
+
+            foreach ($notices as $notice) {
+                if ($this->filter($notice)) {
+                    $filtered[] = $notice;
+                    if (count($filtered) >= $total) {
                         break;
                     }
                 }
@@ -93,9 +98,20 @@ abstract class FilteringNoticeStream extends NoticeStream
             // XXX: make these smarter; factor hit rate into $askFor
 
             $startAt += $askFor;
-            $askFor   = max($total - count($filtered), NOTICES_PER_PAGE);
+            
+            $hits = count($filtered);
+
+            $lastAsk = $askFor;
+
+            if ($hits === 0) {
+                $askFor = max(min(2 * $askFor, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
+            } else {
+                $askFor = max(min(intval(ceil(($total - $hits)*$startAt/$hits)), NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
+            }
 
-        } while (count($filtered) < $total && $results !== 0);
+            $round++;
+
+        } while (count($filtered) < $total && $results >= $lastAsk);
 
         return new ArrayWrapper(array_slice($filtered, $offset, $limit));
     }
@@ -107,9 +123,14 @@ abstract class FilteringNoticeStream extends NoticeStream
         $ids = array();
 
         while ($notices->fetch()) {
-            $ids[] = $notice->id;
+            $ids[] = $notices->id;
         }
 
         return $ids;
     }
+
+    function prefill($notices)
+    {
+        return;
+    }
 }