From dcbcd4731c7ac14cfab2fa96ba7523c8dc7bbe56 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Mar 2012 12:01:27 -0400 Subject: [PATCH] adaptive filtering requests --- lib/filteringnoticestream.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/filteringnoticestream.php b/lib/filteringnoticestream.php index 0b0fab481e..9f3b8ac858 100644 --- a/lib/filteringnoticestream.php +++ b/lib/filteringnoticestream.php @@ -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); -- 2.39.2