From 231075fb495fb0c01b22bb73473961c855a2af94 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 26 Mar 2022 15:08:55 -0500 Subject: [PATCH] artists: fix artist finder to return nothing if it finds too many duplicates --- app/logical/artist_finder.rb | 3 +++ test/unit/artist_test.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/logical/artist_finder.rb b/app/logical/artist_finder.rb index 7c3b5b220..92e3682e7 100644 --- a/app/logical/artist_finder.rb +++ b/app/logical/artist_finder.rb @@ -235,6 +235,9 @@ module ArtistFinder break if url =~ SITE_BLACKLIST_REGEXP end + # Assume no matches if we found too may duplicates. + return Artist.none if artists.size >= 4 + Artist.where(id: artists.uniq.take(20)) end end diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 83bac5588..31a856f38 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -200,6 +200,11 @@ class ArtistTest < ActiveSupport::TestCase assert_artist_found("warhol", "http://warhol.com/x/test.jpg") end + should "not return duplicates if too many artists found" do + create_list(:artist, 5, url_string: "https://www.example.com") + assert_artist_not_found("https://www.example.com/image.jpg") + end + should "not include duplicate urls" do artist = FactoryBot.create(:artist, :url_string => "http://foo.com http://foo.com") assert_equal(["http://foo.com"], artist.url_array)