X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ffilteringnoticestream.php;h=c1edfc63877aad809f6f6d9efe9a5ddd01d32f7e;hb=945920f24dba53d8367160b221bc842db0768fc4;hp=b5def44da7ad092cc71b595e1f012f8bd89fcd68;hpb=d03ca746f2ade65e275bed3b3ad4f3d25442c6ed;p=quix0rs-gnu-social.git diff --git a/lib/filteringnoticestream.php b/lib/filteringnoticestream.php index b5def44da7..c1edfc6387 100644 --- a/lib/filteringnoticestream.php +++ b/lib/filteringnoticestream.php @@ -49,14 +49,17 @@ abstract class FilteringNoticeStream extends NoticeStream { protected $upstream; - function __construct($upstream) + function __construct(NoticeStream $upstream) { $this->upstream = $upstream; } - abstract function filter($notice); + /** + * @return boolean true if we allow it, false if we deny it + */ + abstract protected function filter(Notice $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 +76,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,39 +95,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)