artists: fix artist finder to return nothing if it finds too many duplicates

This commit is contained in:
evazion
2022-03-26 15:08:55 -05:00
parent 44903abe28
commit 231075fb49
2 changed files with 8 additions and 0 deletions

View File

@@ -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

View File

@@ -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)