FIX: prevents SvgSprite.bundle to query ThemeField two times (#9762)

This commit is contained in:
Joffrey JAFFEUX 2020-05-13 17:11:44 +02:00 committed by GitHub
parent d69263f934
commit 9b85e75937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 12 deletions

View File

@ -209,24 +209,26 @@ module SvgSprite
THEME_SPRITE_VAR_NAME = "icons-sprite" THEME_SPRITE_VAR_NAME = "icons-sprite"
def self.custom_svg_sprites(theme_ids = []) def self.custom_svg_sprites(theme_ids = [])
custom_sprite_paths = Dir.glob("#{Rails.root}/plugins/*/svg-icons/*.svg") get_set_cache("custom_svg_sprites_#{Theme.transform_ids(theme_ids).join(',')}") do
custom_sprite_paths = Dir.glob("#{Rails.root}/plugins/*/svg-icons/*.svg")
ThemeField.where(type_id: ThemeField.types[:theme_upload_var], name: THEME_SPRITE_VAR_NAME, theme_id: Theme.transform_ids(theme_ids)) ThemeField.where(type_id: ThemeField.types[:theme_upload_var], name: THEME_SPRITE_VAR_NAME, theme_id: Theme.transform_ids(theme_ids))
.pluck(:upload_id).each do |upload_id| .pluck(:upload_id).each do |upload_id|
upload = Upload.find(upload_id) rescue nil upload = Upload.find(upload_id) rescue nil
if Discourse.store.external? if Discourse.store.external?
external_copy = Discourse.store.download(upload) rescue nil external_copy = Discourse.store.download(upload) rescue nil
original_path = external_copy.try(:path) original_path = external_copy.try(:path)
else else
original_path = Discourse.store.path_for(upload) original_path = Discourse.store.path_for(upload)
end
custom_sprite_paths << original_path if original_path.present?
end end
custom_sprite_paths << original_path if original_path.present? custom_sprite_paths
end end
custom_sprite_paths
end end
def self.all_icons(theme_ids = []) def self.all_icons(theme_ids = [])