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:
Guo Xiang Tan 2020-08-04 14:37:32 +08:00
parent 1f7b44de67
commit 4c03a944f6
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20
1 changed files with 3 additions and 1 deletions

View File

@ -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 || "")