Search: try to compile regexp first before sending to SQL
This commit is contained in:
parent
2fcacd5074
commit
3faf62c53c
|
@ -68,8 +68,14 @@ class Search
|
||||||
|
|
||||||
if domain.present?
|
if domain.present?
|
||||||
self.what = "stories"
|
self.what = "stories"
|
||||||
story_ids = Story.select(:id).where("`url` REGEXP '//([^/]*\.)?" +
|
begin
|
||||||
ActiveRecord::Base.connection.quote_string(domain) + "/'").
|
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)
|
collect(&:id)
|
||||||
|
|
||||||
if story_ids.any?
|
if story_ids.any?
|
||||||
|
|
Loading…
Reference in a new issue