Skip to content

Commit

Permalink
[IPBBridge] Use limit for the number of items
Browse files Browse the repository at this point in the history
The limit was used to specify the number of pages to return from a given
topic which resulted in the number of returned items variing between one
and however many entries are listed on one page.

This commit changes the implementation for the limit to keep loading more
pages until the specified limit is reached. Excessive elements are removed
in order to return the exact amount of items specified by the limit.

This behavior is closer to how other bridges are implemented and makes it
more natural to use without being too confusing. Existing queries must be
updated to account for the new limit.

References #657
  • Loading branch information
logmanoriginal committed Apr 6, 2018
1 parent c899399 commit 1cb83cc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions bridges/IPBBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class IPBBridge extends FeedExpander {
'name' => 'Limit',
'type' => 'number',
'required' => false,
'title' => 'Specify how many pages should be fetched (-1: all)',
'defaultValue' => 1
'title' => 'Specifies the number of items to return on each request (-1: all)',
'defaultValue' => 10
)
)
);
Expand Down Expand Up @@ -161,15 +161,18 @@ private function collectTopicHistory($html, $limit, $callback){

$next = null; // Holds the URI of the next page

do {
// Skip loading HTML on first iteration
if(!is_null($next)) {
$html = getSimpleHTMLDOMCached($next);
while(true) {
$next = $this->$callback($html, is_null($next));

if(is_null($next) || ($limit > 0 && count($this->items) >= $limit)) {
break;
}

$next = $this->$callback($html, is_null($next));
$limit--;
} while(!is_null($next) && $limit <> 0);
$html = getSimpleHTMLDOMCached($next);
}

// We might have more items than specified, remove excess
$this->items = array_slice($this->items, 0, $limit);
}

private function collectTopicArticle($html, $firstrun = true){
Expand Down

0 comments on commit 1cb83cc

Please sign in to comment.