Skip to content

Commit

Permalink
imp: Deduplicate feeds on search pages
Browse files Browse the repository at this point in the history
Sometimes, websites declare all their feeds (atom and rss). We don't
need to display all these feeds to the user. Thus, feeds are
deduplicated if they have the same name.
  • Loading branch information
marienfressinaud committed Oct 4, 2021
1 parent 7cb4ae5 commit 7334bb8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/controllers/links/Searches.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ public function show($request)

$feeds = [];
if ($default_link) {
$feeds = models\Collection::daoToList(
$associated_feeds = models\Collection::daoToList(
'listFeedsWithNumberLinks',
$support_user->id,
$default_link->feedUrls()
);

// Deduplicate feeds with same names
foreach ($associated_feeds as $feed) {
if (!isset($feeds[$feed->name])) {
$feeds[$feed->name] = $feed;
}
}
}

return Response::ok('links/searches/show.phtml', [
Expand Down
40 changes: 40 additions & 0 deletions tests/controllers/links/SearchesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,46 @@ public function testShowDisplaysFeedCollections()
$this->assertStringContainsString($name, $output);
}

public function testShowHidesDuplicatedFeeds()
{
$user = $this->login();
$support_user = models\User::supportUser();
$name = $this->fake('sentence');
$feed_url_rss = $this->fakeUnique('url');
$feed_url_atom = $this->fakeUnique('url');
$collection_rss_id = $this->create('collection', [
'type' => 'feed',
'user_id' => $support_user->id,
'is_public' => 1,
'name' => $name,
'feed_url' => $feed_url_rss,
]);
$collection_atom_id = $this->create('collection', [
'type' => 'feed',
'user_id' => $support_user->id,
'is_public' => 1,
'name' => $name,
'feed_url' => $feed_url_atom,
]);
$link_url = $this->fake('url');
$link_id = $this->create('link', [
'user_id' => $support_user->id,
'url' => $link_url,
'is_hidden' => 0,
'url_feeds' => "[\"{$feed_url_rss}\", \"{$feed_url_atom}\"]",
]);

$response = $this->appRun('get', '/links/search', [
'url' => $link_url,
]);

$this->assertResponseCode($response, 200);
$this->assertResponseContains($response, $collection_rss_id);
// Only the first feed is considered if name are the same but feed
// types differ.
$this->assertResponseNotContains($response, $collection_atom_id);
}

public function testShowDoesNotDisplaysHiddenDefaultLink()
{
$user = $this->login();
Expand Down

0 comments on commit 7334bb8

Please sign in to comment.