PERF: Precompile child theme stylesheets. (#13040)

Previously, we only precompiled the CSS for parent themes but not for
the child themes. As a result, the CSS for child themes were being
compiled during the first request which made the respond time high for
that request.
This commit is contained in:
Alan Guo Xiang Tan
2021-05-20 14:01:54 +08:00
committed by GitHub
parent a532e64389
commit 958b56dc6c
2 changed files with 40 additions and 8 deletions

View File

@ -164,13 +164,23 @@ class Stylesheet::Manager
themes.each do |id, name, color_scheme_id|
targets.each do |target|
theme_id = id || SiteSetting.default_theme_id
next if target =~ THEME_REGEX && theme_id == -1
cache_key = "#{target}_#{theme_id}"
STDERR.puts "precompile target: #{target} #{name}"
builder = self.new(target, theme_id)
builder.compile(force: true)
cache[cache_key] = nil
if target =~ THEME_REGEX
next if theme_id == -1
theme_ids = Theme.transform_ids([theme_id], extend: true)
theme_ids.each do |t_id|
builder = self.new(target, t_id)
STDERR.puts "precompile target: #{target} #{builder.theme.name}"
next if builder.theme.component && !builder.theme.has_scss(target)
builder.compile(force: true)
end
else
STDERR.puts "precompile target: #{target} #{name}"
builder = self.new(target, theme_id)
builder.compile(force: true)
end
end
theme_color_scheme = ColorScheme.find_by_id(color_scheme_id) || ColorScheme.base