Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[FeedMerge] feat: remove duplicates #2888

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion bridges/FeedMergeBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,32 @@ public function collectData()
$this->getInput('feed_4'),
$this->getInput('feed_5'),
];

// Remove empty values
$feeds = array_filter($feeds);

foreach ($feeds as $feed) {
// Fetch all items from the feed
$this->collectExpandableDatas($feed);
}

// Sort by timestamp descending
usort($this->items, fn($a, $b) => $b['timestamp'] <=> $a['timestamp']);

// Remove duplicates
$items = [];
foreach ($this->items as $item) {
$index = $item['uri'] ?? null;
if ($index) {
// Overwrite duplicates
$items[$index] = $item;
} else {
$items[] = $item;
}
}

// Grab the first $limit items
$this->items = array_slice($this->items, 0, $limit);
$this->items = array_slice(array_values($items), 0, $limit);
}

public function getIcon()
Expand Down