aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-02-16 15:10:25 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-02-16 15:34:16 -0800
commit90997f9300eef08d380f2e0fb5874885b5d57a26 (patch)
tree970de495c69d77b6a5cb53fa47c45fce69fd4316
parent497b1350bbfb35ea3e57f5b8363d5d8605930aa6 (diff)
downloadrails-90997f9300eef08d380f2e0fb5874885b5d57a26.tar.gz
rails-90997f9300eef08d380f2e0fb5874885b5d57a26.tar.bz2
rails-90997f9300eef08d380f2e0fb5874885b5d57a26.zip
change internal implementation to use a tree
-rw-r--r--actionview/lib/action_view/digestor.rb24
-rw-r--r--actionview/test/template/digestor_test.rb23
2 files changed, 32 insertions, 15 deletions
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
diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb
index d2d4aec348..37c94d8831 100644
--- a/actionview/test/template/digestor_test.rb
+++ b/actionview/test/template/digestor_test.rb
@@ -36,13 +36,6 @@ class TemplateDigestorTest < ActionView::TestCase
ActionView::Digestor.cache.clear
end
- def test_amaze
- node = ActionView::Digestor.tree "messages/show", finder
- x = ActionView::Digestor.new("messages/show", finder)
- #assert_equal digest("messages/show"), node.to_dep(finder).digest
- assert_equal digest("messages/show"), node.digest
- end
-
def test_top_level_change_reflected
assert_digest_difference("messages/show") do
change_template("messages/show")
@@ -143,6 +136,11 @@ class TemplateDigestorTest < ActionView::TestCase
end
end
+ def test_nested_template_deps
+ nested_deps = ["messages/header", {"comments/comments"=>["comments/comment"]}, "messages/actions/move", "events/event", "messages/something_missing", "messages/something_missing_1", "messages/message", "messages/form"]
+ assert_equal nested_deps, nested_dependencies("messages/show")
+ end
+
def test_recursion_in_renders
assert digest("level/recursion") # assert recursion is possible
assert_not_nil digest("level/recursion") # assert digest is stored
@@ -312,18 +310,17 @@ class TemplateDigestorTest < ActionView::TestCase
finder.variants = options.delete(:variants) || []
node = ActionView::Digestor.tree(template_name, finder, options[:dependencies] || [])
- y = node.digest
- x = ActionView::Digestor.digest({ name: template_name, finder: finder }.merge(options))
- assert_equal x, y
- x
+ node.digest
end
def dependencies(template_name)
- ActionView::Digestor.new(template_name, finder).dependencies
+ tree = ActionView::Digestor.tree(template_name, finder, [])
+ tree.children.map(&:name)
end
def nested_dependencies(template_name)
- ActionView::Digestor.new(template_name, finder).nested_dependencies
+ tree = ActionView::Digestor.tree(template_name, finder, [])
+ tree.children.map(&:to_dep_map)
end
def finder