// or we get nothing from upstream.
$results = null;
+ $round = 0;
do {
+ common_debug(get_class($this) . ": ($offset, $limit) Round $round: fetching $askFor notices starting at $startAt");
+
$raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId);
$results = $raw->N;
break;
}
- $notices = $raw->fetchAll();
-
- // XXX: this should probably only be in the scoping one.
-
- Notice::fillGroups($notices);
- Notice::fillReplies($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) {
// 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((($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.");
+
+ $round++;
+
+ } while (count($filtered) < $total && $results >= $lastAsk);
return new ArrayWrapper(array_slice($filtered, $offset, $limit));
}
return $ids;
}
+
+ function prefill($notices)
+ {
+ return;
+ }
}