PERF: Move URI regexp in `GroupSearchResults.blurb_for` into constant
No need to generate the huge regexp over and over again.
This commit is contained in:
parent
1f7b44de67
commit
4c03a944f6
|
@ -85,12 +85,14 @@ class Search
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
URI_REGEXP = URI.regexp(%w{http https})
|
||||||
|
|
||||||
def self.blurb_for(cooked: nil, term: nil, blurb_length: BLURB_LENGTH, scrub: true)
|
def self.blurb_for(cooked: nil, term: nil, blurb_length: BLURB_LENGTH, scrub: true)
|
||||||
blurb = nil
|
blurb = nil
|
||||||
cooked = SearchIndexer.scrub_html_for_search(cooked) if scrub
|
cooked = SearchIndexer.scrub_html_for_search(cooked) if scrub
|
||||||
|
|
||||||
urls = Set.new
|
urls = Set.new
|
||||||
cooked.scan(URI.regexp(%w{http https})) { urls << $& }
|
cooked.scan(URI_REGEXP) { urls << $& }
|
||||||
urls.each do |url|
|
urls.each do |url|
|
||||||
begin
|
begin
|
||||||
case File.extname(URI(url).path || "")
|
case File.extname(URI(url).path || "")
|
||||||
|
|
Loading…
Reference in New Issue