Last active
October 31, 2020 15:34
-
-
Save elia/8d78d1b1a52cc2ed88c665b32a139182 to your computer and use it in GitHub Desktop.
Sprockets patch for https://github.com/rails/sprockets/issues/242
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove when https://github.com/rails/sprockets/issues/242 is resolved | |
unless Rails.env.development? | |
module SprocketsCachedLoader | |
def initialize(*) | |
super | |
@expanded_assets_cache = {} | |
end | |
def asset_from_cache(key) | |
return @expanded_assets_cache[key] if @expanded_assets_cache.key?(key) | |
asset = cache.get(key, true) | |
if asset | |
asset[:uri] = expand_from_root(asset[:uri]) | |
asset[:load_path] = expand_from_root(asset[:load_path]) | |
asset[:filename] = expand_from_root(asset[:filename]) | |
asset[:metadata][:included] = asset[:metadata][:included].map { |uri| expand_from_root(uri) } if asset[:metadata][:included] | |
asset[:metadata][:links] = asset[:metadata][:links].map { |uri| expand_from_root(uri) } if asset[:metadata][:links] | |
asset[:metadata][:stubbed] = asset[:metadata][:stubbed].map { |uri| expand_from_root(uri) } if asset[:metadata][:stubbed] | |
asset[:metadata][:required] = asset[:metadata][:required].map { |uri| expand_from_root(uri) } if asset[:metadata][:required] | |
asset[:metadata][:dependencies] = asset[:metadata][:dependencies].map { |uri| uri.start_with?("file-digest://") ? expand_from_root(uri) : uri } if asset[:metadata][:dependencies] | |
asset[:metadata].each_key do |k| | |
next unless k =~ /_dependencies\z/ | |
asset[:metadata][k] = asset[:metadata][k].map { |uri| expand_from_root(uri) } | |
end | |
asset | |
end | |
@expanded_assets_cache[key] = asset | |
end | |
Sprockets::CachedEnvironment.prepend self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On line 10, I believe it is @expanded_assets_cache.has_key?(key)