X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffilteringnoticestream.php;h=b4ec6687bb7c92831ed30114d0de9847cfdbab45;hb=931753229328d0ebdf80b76b898a736c06dc70a4;hp=eb51076b7c217980768f66db37d19d56aae21382;hpb=9b0279c2d5299379275f805203b1bd0f79900e9d;p=quix0rs-gnu-social.git diff --git a/lib/filteringnoticestream.php b/lib/filteringnoticestream.php index eb51076b7c..b4ec6687bb 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=null, $maxId=null) + function getNoticeIds($offset, $limit, $since_id, $max_id) { // "offset" is virtual; we have to get a lot $total = $offset + $limit; @@ -73,24 +73,18 @@ abstract class FilteringNoticeStream extends NoticeStream $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); + $raw = $this->upstream->getNotices($startAt, $askFor, $since_id, $max_id); $results = $raw->N; - if ($results == 0) { break; } $notices = $raw->fetchAll(); - $this->prefill($notices); - foreach ($notices as $notice) { if ($this->filter($notice)) { - $filtered[] = $notice; + $filtered[] = $notice->id; if (count($filtered) >= $total) { break; } @@ -98,37 +92,20 @@ abstract class FilteringNoticeStream extends NoticeStream } // XXX: make these smarter; factor hit rate into $askFor - $startAt += $askFor; - $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); + $askFor = max(min(intval(ceil(($total - $hits)*$startAt/$hits)), NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE); } - 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)); - } - - function getNoticeIds($offset, $limit, $sinceId, $maxId) - { - $notices = $this->getNotices($offset, $limit, $sinceId, $maxId); - - $ids = array(); - - while ($notices->fetch()) { - $ids[] = $notices->id; - } - - return $ids; + return array_slice(array_values($filtered), $offset, $limit); } function prefill($notices)