FilteringNoticeStream now uses OOP for getNotices
getNoticeIds gives the notices to fetch, which are caught by getNotices in a parent class.
This commit is contained in:
parent
8f8a7dbde0
commit
e0014b6736
@ -56,7 +56,7 @@ abstract class FilteringNoticeStream extends NoticeStream
|
|||||||
|
|
||||||
abstract function filter($notice);
|
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
|
// "offset" is virtual; we have to get a lot
|
||||||
$total = $offset + $limit;
|
$total = $offset + $limit;
|
||||||
@ -73,22 +73,18 @@ abstract class FilteringNoticeStream extends NoticeStream
|
|||||||
$round = 0;
|
$round = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
$raw = $this->upstream->getNotices($startAt, $askFor, $since_id, $max_id);
|
||||||
$raw = $this->upstream->getNotices($startAt, $askFor, $sinceId, $maxId);
|
|
||||||
|
|
||||||
$results = $raw->N;
|
$results = $raw->N;
|
||||||
|
|
||||||
if ($results == 0) {
|
if ($results == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$notices = $raw->fetchAll();
|
$notices = $raw->fetchAll();
|
||||||
|
|
||||||
$this->prefill($notices);
|
$this->prefill($notices);
|
||||||
|
|
||||||
foreach ($notices as $notice) {
|
foreach ($notices as $notice) {
|
||||||
if ($this->filter($notice)) {
|
if ($this->filter($notice)) {
|
||||||
$filtered[] = $notice;
|
$filtered[] = $notice->id;
|
||||||
if (count($filtered) >= $total) {
|
if (count($filtered) >= $total) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -96,11 +92,8 @@ abstract class FilteringNoticeStream extends NoticeStream
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX: make these smarter; factor hit rate into $askFor
|
// XXX: make these smarter; factor hit rate into $askFor
|
||||||
|
|
||||||
$startAt += $askFor;
|
$startAt += $askFor;
|
||||||
|
|
||||||
$hits = count($filtered);
|
$hits = count($filtered);
|
||||||
|
|
||||||
$lastAsk = $askFor;
|
$lastAsk = $askFor;
|
||||||
|
|
||||||
if ($hits === 0) {
|
if ($hits === 0) {
|
||||||
@ -110,23 +103,9 @@ abstract class FilteringNoticeStream extends NoticeStream
|
|||||||
}
|
}
|
||||||
|
|
||||||
$round++;
|
$round++;
|
||||||
|
|
||||||
} while (count($filtered) < $total && $results >= $lastAsk);
|
} while (count($filtered) < $total && $results >= $lastAsk);
|
||||||
|
|
||||||
return new ArrayWrapper(array_slice($filtered, $offset, $limit));
|
return array_slice(array_values($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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function prefill($notices)
|
function prefill($notices)
|
||||||
|
Loading…
Reference in New Issue
Block a user