From 73663c2fdbd238d5f5eacc7b37eb2730c28e52a6 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Tue, 9 Apr 2019 18:48:49 +0530 Subject: [PATCH] FIX: should find records by sha1 only in Upload model --- app/models/concerns/has_url.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/has_url.rb b/app/models/concerns/has_url.rb index e7f5f61bdec..8b92f6ab658 100644 --- a/app/models/concerns/has_url.rb +++ b/app/models/concerns/has_url.rb @@ -17,9 +17,13 @@ module HasUrl return if uri&.path.blank? data = extract_url(uri.path) return if data.blank? - sha1 = data[2] result = nil - result = self.find_by(sha1: sha1) if sha1&.length == Upload::SHA1_LENGTH + + if self.name == "Upload" + sha1 = data[2] + result = self.find_by(sha1: sha1) if sha1&.length == Upload::SHA1_LENGTH + end + result || self.find_by("url LIKE ?", "%#{data[1]}") end end