From a166899633e96a9aff84e7615cd1e38c21ebe2fa Mon Sep 17 00:00:00 2001 From: Dag Date: Wed, 22 Jun 2022 18:34:05 +0200 Subject: [PATCH] [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 --- bridges/FeedMergeBridge.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bridges/FeedMergeBridge.php b/bridges/FeedMergeBridge.php index ff13ac9e..b90055e5 100644 --- a/bridges/FeedMergeBridge.php +++ b/bridges/FeedMergeBridge.php @@ -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() {