X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ffilteringnoticestream.php;h=979305ad39f57cf176e6876df236fe2eb0270689;hb=b4271a3533bdf12329f27dd75452c1ef2a6ee3d1;hp=221e9cd70591302d33f4644a0f8012b51a3cfee6;hpb=36d724cf03f5c0a29c9a30c2fb51d631a7f1edba;p=quix0rs-gnu-social.git diff --git a/lib/filteringnoticestream.php b/lib/filteringnoticestream.php index 221e9cd705..979305ad39 100644 --- a/lib/filteringnoticestream.php +++ b/lib/filteringnoticestream.php @@ -49,14 +49,14 @@ abstract class FilteringNoticeStream extends NoticeStream { protected $upstream; - function __construct($upstream) + function __construct(NoticeStream $upstream) { $this->upstream = $upstream; } - abstract function filter($notice); + 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,22 +73,18 @@ abstract class FilteringNoticeStream extends NoticeStream $round = 0; do { - - $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; } @@ -96,11 +92,8 @@ abstract class FilteringNoticeStream extends NoticeStream } // XXX: make these smarter; factor hit rate into $askFor - $startAt += $askFor; - $hits = count($filtered); - $lastAsk = $askFor; if ($hits === 0) { @@ -110,23 +103,9 @@ abstract class FilteringNoticeStream extends NoticeStream } $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)