Open ledestin opened 4 years ago
I spent most of my afternoon hunting this bug and I had the same conclusion as yours. Our assets pipeline went from almost 2 minutes to 30 seconds with this fix.
Indeed, I just spent most of my evening on this one :)
Problem
Running a single system test takes about 50 seconds on a project with lots of SASS files. I've investigated Sprockets and found out that SASS files are processed each time a test runs, and Sprockets cache isn't used. And it is not used, because of a random cache key in
SassCompressor
.SassCompressor is monkey patched by sassc-rails and uses a random
#cache_key
: https://github.com/sass/sassc-rails/blob/bf66eadae454624ea328f415370a323ecab7cf2f/lib/sassc/rails/compressor.rb#L14Possible solution
Sprockets uses the following cache key:
@cache_key = "#{self.class.name}:#{Autoload::Sass::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
https://github.com/rails/sprockets/blob/386ab2ba215f828602b6e6bfee9bfc95dc23d574/lib/sprockets/sass_compressor.rb#L46By using the Sprockets
@cache_key
code, I was able to make the test 2x faster (50 -> 25 seconds).Would it be possible to use a cache key that doesn't change on each run, when no other things have changed?