Search: try to compile regexp first before sending to SQL

This commit is contained in:
Carl Chenet 2017-05-19 14:01:10 +02:00
parent 2fcacd5074
commit 3faf62c53c

View file

@ -68,8 +68,14 @@ class Search
if domain.present?
self.what = "stories"
story_ids = Story.select(:id).where("`url` REGEXP '//([^/]*\.)?" +
ActiveRecord::Base.connection.quote_string(domain) + "/'").
begin
reg = Regexp.new("//([^/]*\.)?#{domain}/")
rescue RegexpError
return false
end
story_ids = Story.select(:id).where("`url` REGEXP '" +
ActiveRecord::Base.connection.quote_string(reg.source) + "'").
collect(&:id)
if story_ids.any?