PERF: Improve cook_url performance for topic thumbnails (#11609)

- Only initialize the S3Helper when needed
- Skip initializing the S3Helper for S3Store#cdn_url
- Allow cook_url to be passed a `local` hint to skip unnecessary checks
This commit is contained in:
David Taylor
2020-12-30 18:13:13 +00:00
committed by GitHub
parent 1cd6ff15dc
commit 13e39d8b9f
5 changed files with 25 additions and 22 deletions

View File

@@ -88,7 +88,7 @@ class Topic < ActiveRecord::Base
Jobs.enqueue(:generate_topic_thumbnails, { topic_id: id, extra_sizes: extra_sizes })
end
infos.each { |i| i[:url] = UrlHelper.cook_url(i[:url], secure: original.secure?) }
infos.each { |i| i[:url] = UrlHelper.cook_url(i[:url], secure: original.secure?, local: true) }
infos.sort_by! { |i| -i[:width] * i[:height] }
end
@@ -123,7 +123,7 @@ class Topic < ActiveRecord::Base
end
raw_url = thumbnail&.optimized_image&.url || image_upload&.url
UrlHelper.cook_url(raw_url, secure: image_upload&.secure?)
UrlHelper.cook_url(raw_url, secure: image_upload&.secure?, local: true) if raw_url
end
def featured_users