[FeedMerge] fix bugs (#2854)

* [FeedMerge] fix: sort items by timestamp descending

* [FeedMerge] fix: fetch 10 most recent items

This fixes a bug where the bridge e.g. fetched 10 items from the first feed and then nothing from the rest
This commit is contained in:
Dag 2022-06-22 18:34:05 +02:00 committed by GitHub
parent 7dc3449207
commit a166899633
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -25,11 +25,13 @@ TEXT;
'feed_3' => ['name' => 'Feed url', 'type' => 'text'],
'feed_4' => ['name' => 'Feed url', 'type' => 'text'],
'feed_5' => ['name' => 'Feed url', 'type' => 'text'],
'limit' => self::LIMIT,
]
];
public function collectData() {
$limit = 10;
$limit = (int)($this->getInput('limit') ?: 10);
$feeds = [
$this->getInput('feed_1'),
$this->getInput('feed_2'),
@ -40,8 +42,13 @@ TEXT;
// Remove empty values
$feeds = array_filter($feeds);
foreach ($feeds as $feed) {
$this->collectExpandableDatas($feed, $limit);
// Fetch all items from the feed
$this->collectExpandableDatas($feed);
}
// Sort by timestamp descending
usort($this->items, fn($a, $b) => $b['timestamp'] <=> $a['timestamp']);
// Grab the first $limit items
$this->items = array_slice($this->items, 0, $limit);
}
public function getIcon() {