diff --git a/app/models/upload.rb b/app/models/upload.rb index 349ab31fd4e..afe9dbd2bed 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -87,6 +87,8 @@ class Upload < ActiveRecord::Base path = uri.path[/(\/original\/\dX\/[\/\.\w]+)/, 1] + return if path.blank? + Upload.find_by("url LIKE ?", "%#{path}") end diff --git a/lib/search.rb b/lib/search.rb index f6f026a0cab..057d50e7c17 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -476,13 +476,17 @@ class Search advanced_filter(/filetypes?:([a-zA-Z0-9,\-_]+)/) do |posts, match| file_extensions = match.split(",").map(&:downcase) posts.where("posts.id IN ( - SELECT post_id FROM topic_links - WHERE extension IN (:file_extensions) + SELECT post_id + FROM topic_links + WHERE extension IN (:file_extensions) + UNION - SELECT post_uploads.post_id FROM uploads - JOIN post_uploads ON post_uploads.upload_id = uploads.id - WHERE lower(uploads.extension) IN (:file_extensions) - )", file_extensions: file_extensions) + + SELECT post_uploads.post_id + FROM uploads + JOIN post_uploads ON post_uploads.upload_id = uploads.id + WHERE lower(uploads.extension) IN (:file_extensions) + )", file_extensions: file_extensions) end private