PERF: optimize homepage and topic performance (#11607)

These are a few small tweaks that slightly improve performance.

- we omitted 1 query from the post guardian which could cause an N+1
- cook_url has been sped up a bit
- url helper avoids re-creating sets for no reason
This commit is contained in:
Sam
2020-12-31 00:08:02 +11:00
committed by GitHub
parent e0c952290b
commit 1cd6ff15dc
3 changed files with 24 additions and 17 deletions

View File

@ -14,15 +14,15 @@ class FileHelper
end
def self.is_supported_image?(filename)
(filename =~ supported_images_regexp).present?
filename.match?(supported_images_regexp)
end
def self.is_inline_image?(filename)
(filename =~ inline_images_regexp).present?
filename.match?(inline_images_regexp)
end
def self.is_supported_media?(filename)
(filename =~ supported_media_regexp).present?
filename.match?(supported_media_regexp)
end
class FakeIO
@ -162,7 +162,10 @@ class FileHelper
end
def self.supported_media_regexp
media = supported_images | supported_audio | supported_video
@@supported_media_regexp ||= /\.(#{media.to_a.join("|")})$/i
@@supported_media_regexp ||=
begin
media = supported_images | supported_audio | supported_video
/\.(#{media.to_a.join("|")})$/i
end
end
end