mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 19:03:48 +08:00
PERF: speed up css precompilation by caching
This commit is contained in:
parent
28f84ef0e1
commit
f602c568e2
|
@ -18,20 +18,40 @@ task 'assets:precompile:before' do
|
|||
require 'digest/sha1'
|
||||
|
||||
module ::Sprockets
|
||||
class UglifierCompressor
|
||||
def evaluate(context, locals, &block)
|
||||
|
||||
digest = Digest::SHA1.hexdigest(data)
|
||||
key = "SPROCKETS_#{digest}"
|
||||
|
||||
if compiled = $redis.get(key)
|
||||
$redis.expire(key, 1.week)
|
||||
else
|
||||
compiled = Uglifier.new(:comments => :none).compile(data)
|
||||
$redis.setex(key, 1.week, compiled)
|
||||
end
|
||||
compiled
|
||||
def self.cache_compiled(type, data)
|
||||
digest = Digest::SHA1.hexdigest(data)
|
||||
key = "SPROCKETS_#{type}_#{digest}"
|
||||
if compiled = $redis.get(key)
|
||||
$redis.expire(key, 1.week)
|
||||
else
|
||||
compiled = yield
|
||||
$redis.setex(key, 1.week, compiled)
|
||||
end
|
||||
compiled
|
||||
end
|
||||
|
||||
class SassCompressor
|
||||
def evaluate(context, locals, &block)
|
||||
::Sprockets.cache_compiled("sass", data) do
|
||||
::Sass::Engine.new(data, {
|
||||
:syntax => :scss,
|
||||
:cache => false,
|
||||
:read_cache => false,
|
||||
:style => :compressed
|
||||
}).render
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class UglifierCompressor
|
||||
|
||||
def evaluate(context, locals, &block)
|
||||
::Sprockets.cache_compiled("uglifier", data) do
|
||||
Uglifier.new(:comments => :none).compile(data)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user