mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:52:11 +08:00
PERF: Preload settings, groups and badge icons in SvgSprite.
Identified as a hot path in production. Preload it early instead of executing the queries in a live request.
This commit is contained in:
parent
eb2c399445
commit
58b30fb510
|
@ -930,6 +930,7 @@ module Discourse
|
|||
|
||||
JsLocaleHelper.load_translations(SiteSetting.default_locale)
|
||||
Site.json_for(Guardian.new)
|
||||
SvgSprite.preload
|
||||
end
|
||||
|
||||
[
|
||||
|
|
|
@ -221,6 +221,12 @@ module SvgSprite
|
|||
|
||||
THEME_SPRITE_VAR_NAME = "icons-sprite"
|
||||
|
||||
def self.preload
|
||||
settings_icons
|
||||
group_icons
|
||||
badge_icons
|
||||
end
|
||||
|
||||
def self.custom_svg_sprites(theme_ids = [])
|
||||
get_set_cache("custom_svg_sprites_#{Theme.transform_ids(theme_ids).join(',')}") do
|
||||
custom_sprite_paths = Dir.glob("#{Rails.root}/plugins/*/svg-icons/*.svg")
|
||||
|
@ -415,6 +421,7 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
|||
end
|
||||
|
||||
def self.settings_icons
|
||||
get_set_cache("settings_icons") do
|
||||
# includes svg_icon_subset and any settings containing _icon (incl. plugin settings)
|
||||
site_setting_icons = []
|
||||
|
||||
|
@ -426,18 +433,23 @@ License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL
|
|||
|
||||
site_setting_icons
|
||||
end
|
||||
end
|
||||
|
||||
def self.plugin_icons
|
||||
DiscoursePluginRegistry.svg_icons
|
||||
end
|
||||
|
||||
def self.badge_icons
|
||||
get_set_cache("badge_icons") do
|
||||
Badge.pluck(:icon).uniq
|
||||
end
|
||||
end
|
||||
|
||||
def self.group_icons
|
||||
get_set_cache("group_icons") do
|
||||
Group.pluck(:flair_icon).uniq
|
||||
end
|
||||
end
|
||||
|
||||
def self.theme_icons(theme_ids)
|
||||
return [] if theme_ids.blank?
|
||||
|
|
Loading…
Reference in New Issue
Block a user