X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ffilteringnoticestream.php;h=221e9cd70591302d33f4644a0f8012b51a3cfee6;hb=2e3ef4cc078a29be245c6b19f5c8d900d9fe75cc;hp=96b9432fc152bacddb80ad4f42d3e246dd9bbc88;hpb=1e73ba00bdd37f46415eb45b1b904dc894fb801c;p=quix0rs-gnu-social.git diff --git a/lib/filteringnoticestream.php b/lib/filteringnoticestream.php index 96b9432fc1..221e9cd705 100644 --- a/lib/filteringnoticestream.php +++ b/lib/filteringnoticestream.php @@ -56,7 +56,7 @@ abstract class FilteringNoticeStream extends NoticeStream abstract function filter($notice); - function getNotices($offset, $limit, $sinceId, $maxId) + function getNotices($offset, $limit, $sinceId=null, $maxId=null) { // "offset" is virtual; we have to get a lot $total = $offset + $limit; @@ -70,6 +70,7 @@ abstract class FilteringNoticeStream extends NoticeStream // or we get nothing from upstream. $results = null; + $round = 0; do { @@ -81,9 +82,13 @@ abstract class FilteringNoticeStream extends NoticeStream break; } - while ($raw->fetch()) { - if ($this->filter($raw)) { - $filtered[] = clone($raw); + $notices = $raw->fetchAll(); + + $this->prefill($notices); + + foreach ($notices as $notice) { + if ($this->filter($notice)) { + $filtered[] = $notice; if (count($filtered) >= $total) { break; } @@ -93,9 +98,20 @@ 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); + + $lastAsk = $askFor; + + if ($hits === 0) { + $askFor = max(min(2 * $askFor, NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE); + } else { + $askFor = max(min(intval(ceil(($total - $hits)*$startAt/$hits)), NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE); + } - } while (count($filtered) < $total && $results !== 0); + $round++; + + } while (count($filtered) < $total && $results >= $lastAsk); return new ArrayWrapper(array_slice($filtered, $offset, $limit)); } @@ -112,4 +128,9 @@ abstract class FilteringNoticeStream extends NoticeStream return $ids; } + + function prefill($notices) + { + return; + } }