mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FEATURE: much faster asset precompilation with a redis backed cache
This commit is contained in:
parent
d132fd0609
commit
a69f59ef51
1 changed files with 22 additions and 0 deletions
|
@ -8,6 +8,28 @@ task 'assets:precompile:before' do
|
|||
# in the past we applied a patch that removed asset postfixes, but it is terrible practice
|
||||
# leaving very complicated build issues
|
||||
# https://github.com/rails/sprockets-rails/issues/49
|
||||
|
||||
# let's make precompile faster using redis magic
|
||||
require 'sprockets'
|
||||
require 'digest/sha1'
|
||||
|
||||
module ::Sprockets
|
||||
class UglifierCompressor
|
||||
def evaluate(context, locals, &block)
|
||||
|
||||
digest = Digest::SHA1.hexdigest(data)
|
||||
key = "SPROCKETS_#{digest}"
|
||||
|
||||
unless compiled = $redis.get(key)
|
||||
compiled = Uglifier.new(:comments => :none).compile(data)
|
||||
$redis.setex(key, 1.week, compiled)
|
||||
end
|
||||
$redis.expire(key, 1.week)
|
||||
compiled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
task 'assets:precompile' => 'assets:precompile:before'
|
||||
|
|
Loading…
Reference in a new issue