]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
adaptive filtering requests
authorEvan Prodromou <evan@status.net>
Wed, 21 Mar 2012 16:01:27 +0000 (12:01 -0400)
committerEvan Prodromou <evan@status.net>
Wed, 21 Mar 2012 16:01:27 +0000 (12:01 -0400)
lib/filteringnoticestream.php

index 0b0fab481eb37393a1e336bab9ada36d7e65b63a..9f3b8ac8584b02ac66b8cf5074d7364b04b6c7c0 100644 (file)
@@ -72,6 +72,7 @@ abstract class FilteringNoticeStream extends NoticeStream
         $results = null;
 
         do {
+            common_debug(get_class($this) . ": ($offset, $limit) fetching $askFor notices starting at $startAt");
 
             $raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId);
 
@@ -100,7 +101,14 @@ 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);
+
+            if ($hits === 0) {
+                $askFor = max(min(2 * $askFor, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
+            } else {
+                $askFor = max(min((($total - $hits)*$startAt)/$hits, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
+            }
 
         } while (count($filtered) < $total && $results !== 0);