123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- abstract class FilteringNoticeStream extends NoticeStream
- {
- protected $upstream;
- function __construct(NoticeStream $upstream)
- {
- $this->upstream = $upstream;
- }
-
- abstract protected function filter(Notice $notice);
- function getNoticeIds($offset, $limit, $since_id, $max_id)
- {
-
- $total = $offset + $limit;
- $filtered = array();
- $startAt = 0;
- $askFor = $total;
-
-
- $results = null;
- $round = 0;
- do {
- $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->id;
- if (count($filtered) >= $total) {
- break;
- }
- }
- }
-
- $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(intval(ceil(($total - $hits)*$startAt/$hits)), NOTICES_PER_PAGE * 50), NOTICES_PER_PAGE);
- }
- $round++;
- } while (count($filtered) < $total && $results >= $lastAsk);
- return array_slice(array_values($filtered), $offset, $limit);
- }
- function prefill($notices)
- {
- return;
- }
- }
|