From 90997f9300eef08d380f2e0fb5874885b5d57a26 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 16 Feb 2016 15:10:25 -0800 Subject: change internal implementation to use a tree --- actionview/lib/action_view/digestor.rb | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'actionview/lib') diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index 9b51579117..78c141dafc 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -25,17 +25,22 @@ module ActionView def digest(name:, finder:, **options) options.assert_valid_keys(:dependencies, :partial) - cache_key = ([ name, finder.details_key.hash ].compact + Array.wrap(options[:dependencies])).join('.') + dependencies = Array.wrap(options[:dependencies]) + cache_key = ([ name, finder.details_key.hash ].compact + dependencies).join('.') # this is a correctly done double-checked locking idiom # (Concurrent::Map's lookups have volatile semantics) @@cache[cache_key] || @@digest_monitor.synchronize do @@cache.fetch(cache_key) do # re-check under lock - compute_and_store_digest(cache_key, name, finder, options) + @@cache[cache_key] = tree(name, finder, dependencies).digest end end end + def logger + ActionView::Base.logger || NullLogger + end + private def compute_and_store_digest(cache_key, name, finder, options) # called under @@digest_monitor lock klass = if options[:partial] || name.include?("/_") @@ -77,6 +82,7 @@ module ActionView node end else + logger.error " '#{name}' file doesn't exist, so no dependencies" seen[name] ||= Missing.new(name, logical_name, nil) end end @@ -116,6 +122,10 @@ module ActionView end end.join("-") end + + def to_dep_map + children.any? ? { name => children.map(&:to_dep_map) } : name + end end class Partial < Node @@ -126,8 +136,18 @@ module ActionView class Missing < Node def digest(_ = []) + logger.error " Couldn't find template for digesting: #{name}" '' end + + class NullLogger + def self.debug(_); end + def self.error(_); end + end + + def logger + ActionView::Base.logger || NullLogger + end end class Injected < Node -- cgit v1.2.3