Skip to content

A platform for community discussion. Free, open, simple.

PERF: Hydrate stylesheets from the cache table before compiling

Régis Hanolb5c670e9e650
diff --git a/lib/stylesheet/manager/builder.rb b/lib/stylesheet/manager/builder.rb
index 8618298aab5..818e5baadef 100644
--- a/lib/stylesheet/manager/builder.rb
+++ b/lib/stylesheet/manager/builder.rb
@@ -33,6 +33,8 @@ class Stylesheet::Manager::Builder
end
return true
end
+
+ return true if hydrate_from_cache!
end
rtl = @target.to_s.end_with?("_rtl")
diff --git a/spec/lib/stylesheet/manager_spec.rb b/spec/lib/stylesheet/manager_spec.rb
index d6d6c3a923c..7a03d5df493 100644
--- a/spec/lib/stylesheet/manager_spec.rb
+++ b/spec/lib/stylesheet/manager_spec.rb
@@ -18,6 +18,20 @@ RSpec.describe Stylesheet::Manager do
expect(link).not_to eq("")
end
+ describe "Builder#compile" do
+ it "hydrates from StylesheetCache instead of recompiling when the file is missing" do
+ builder = Stylesheet::Manager::Builder.new(target: :common, manager: manager)
+ Stylesheet::Manager.rm_cache_folder
+ StylesheetCache.where(target: builder.qualified_target, digest: builder.digest).delete_all
+ StylesheetCache.add(builder.qualified_target, builder.digest, "body{}", nil)
+ Stylesheet::Compiler.expects(:compile_asset).never
+
+ builder.compile
+
+ expect(File.read(builder.stylesheet_fullpath)).to eq("body{}")
+ end
+ end
+
describe "themes with components" do
let(:child_theme) do
Fabricate(:theme, component: true, name: "a component").tap do |c|