]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/filteringnoticestream.php
Merge remote-tracking branch 'statusnet/master'
[quix0rs-gnu-social.git] / lib / filteringnoticestream.php
index 267955dfd95ba134930bac405dc1e12e07ca29d3..221e9cd70591302d33f4644a0f8012b51a3cfee6 100644 (file)
@@ -70,6 +70,7 @@ abstract class FilteringNoticeStream extends NoticeStream
         // or we get nothing from upstream.
 
         $results = null;
+        $round = 0;
 
         do {
 
@@ -81,13 +82,11 @@ abstract class FilteringNoticeStream extends NoticeStream
                 break;
             }
 
-                       $notices = $raw->fetchAll();
-                       
-                       // XXX: this should probably only be in the scoping one.
-                       
-                       Notice::fillGroups($notices);
-                       
-                       foreach ($notices as $notice) {
+            $notices = $raw->fetchAll();
+            
+            $this->prefill($notices);
+
+            foreach ($notices as $notice) {
                 if ($this->filter($notice)) {
                     $filtered[] = $notice;
                     if (count($filtered) >= $total) {
@@ -99,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));
     }
@@ -118,4 +128,9 @@ abstract class FilteringNoticeStream extends NoticeStream
 
         return $ids;
     }
+
+    function prefill($notices)
+    {
+        return;
+    }
 }