From 0d8dd9078c040a600a0f8d99320b606362467b51 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 21 Mar 2012 12:21:36 -0400 Subject: [PATCH] Don't fetch more than needed if exhausted --- lib/filteringnoticestream.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/filteringnoticestream.php b/lib/filteringnoticestream.php index 119f71e404..eb51076b7c 100644 --- a/lib/filteringnoticestream.php +++ b/lib/filteringnoticestream.php @@ -70,9 +70,11 @@ abstract class FilteringNoticeStream extends NoticeStream // or we get nothing from upstream. $results = null; + $round = 0; do { - common_debug(get_class($this) . ": ($offset, $limit) fetching $askFor notices starting at $startAt"); + + common_debug(get_class($this) . ": ($offset, $limit) Round $round: fetching $askFor notices starting at $startAt"); $raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId); @@ -101,13 +103,17 @@ abstract class FilteringNoticeStream extends NoticeStream $hits = count($filtered); + $lastAsk = $askFor; + 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); + common_debug(get_class($this) . ": ($offset, $limit) Round $round hits is $hits, results = $results."); + + } while (count($filtered) < $total && $results >= $lastAsk); return new ArrayWrapper(array_slice($filtered, $offset, $limit)); } -- 2.39.5