forked from blallo/rss-bridge
[IPBBridge] Use limit for the number of items
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
This commit is contained in:
parent
c899399569
commit
1cb83ccea3
1 changed files with 12 additions and 9 deletions
|
@ -18,8 +18,8 @@ class IPBBridge extends FeedExpander {
|
||||||
'name' => 'Limit',
|
'name' => 'Limit',
|
||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'title' => 'Specify how many pages should be fetched (-1: all)',
|
'title' => 'Specifies the number of items to return on each request (-1: all)',
|
||||||
'defaultValue' => 1
|
'defaultValue' => 10
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -161,15 +161,18 @@ class IPBBridge extends FeedExpander {
|
||||||
|
|
||||||
$next = null; // Holds the URI of the next page
|
$next = null; // Holds the URI of the next page
|
||||||
|
|
||||||
do {
|
while(true) {
|
||||||
// Skip loading HTML on first iteration
|
$next = $this->$callback($html, is_null($next));
|
||||||
if(!is_null($next)) {
|
|
||||||
|
if(is_null($next) || ($limit > 0 && count($this->items) >= $limit)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
$html = getSimpleHTMLDOMCached($next);
|
$html = getSimpleHTMLDOMCached($next);
|
||||||
}
|
}
|
||||||
|
|
||||||
$next = $this->$callback($html, is_null($next));
|
// We might have more items than specified, remove excess
|
||||||
$limit--;
|
$this->items = array_slice($this->items, 0, $limit);
|
||||||
} while(!is_null($next) && $limit <> 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function collectTopicArticle($html, $firstrun = true){
|
private function collectTopicArticle($html, $firstrun = true){
|
||||||
|
|
Loading…
Reference in a new issue