PERF: Reduce N+1s on theme admin page

This commit is contained in:
David Taylor
2019-02-26 14:22:02 +00:00
parent d04c4bf8e7
commit a8ffc02d06
5 changed files with 25 additions and 19 deletions

View File

@@ -142,13 +142,15 @@ class ColorScheme < ActiveRecord::Base
@mutex = Mutex.new
def self.base_colors
return @base_colors if @base_colors
@mutex.synchronize do
return @base_colors if @base_colors
@base_colors = {}
base_colors = {}
File.readlines(BASE_COLORS_FILE).each do |line|
matches = /\$([\w]+):\s*#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})(?:[;]|\s)/.match(line.strip)
@base_colors[matches[1]] = matches[2] if matches
base_colors[matches[1]] = matches[2] if matches
end
@base_colors = base_colors
end
@base_colors
end