Don't fetch more than needed if exhausted
This commit is contained in:
parent
0238aa9d19
commit
9b0279c2d5
|
@ -70,9 +70,11 @@ abstract class FilteringNoticeStream extends NoticeStream
|
||||||
// or we get nothing from upstream.
|
// or we get nothing from upstream.
|
||||||
|
|
||||||
$results = null;
|
$results = null;
|
||||||
|
$round = 0;
|
||||||
|
|
||||||
do {
|
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);
|
$raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId);
|
||||||
|
|
||||||
|
@ -101,13 +103,17 @@ abstract class FilteringNoticeStream extends NoticeStream
|
||||||
|
|
||||||
$hits = count($filtered);
|
$hits = count($filtered);
|
||||||
|
|
||||||
|
$lastAsk = $askFor;
|
||||||
|
|
||||||
if ($hits === 0) {
|
if ($hits === 0) {
|
||||||
$askFor = max(min(2 * $askFor, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
|
$askFor = max(min(2 * $askFor, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
|
||||||
} else {
|
} else {
|
||||||
$askFor = max(min((($total - $hits)*$startAt)/$hits, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
|
$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));
|
return new ArrayWrapper(array_slice($filtered, $offset, $limit));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user