PERF: Memoize calls to ApplicationHelper#scheme_id.

The same query was executed 4 times per full page load.
This commit is contained in:
Guo Xiang Tan 2020-09-09 15:15:15 +08:00
parent 9b75d95fc6
commit fb7bbae3f4
No known key found for this signature in database
GPG Key ID: FBD110179AAC1F20

View File

@ -402,13 +402,16 @@ module ApplicationHelper
end
def scheme_id
return @scheme_id if defined?(@scheme_id)
custom_user_scheme_id = cookies[:color_scheme_id] || current_user&.user_option&.color_scheme_id
if custom_user_scheme_id && ColorScheme.find_by_id(custom_user_scheme_id)
return custom_user_scheme_id
end
return if theme_ids.blank?
Theme
@scheme_id = Theme
.where(id: theme_ids.first)
.pluck(:color_scheme_id)
.first