1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #33817 from schneems/schneems/dig-simple

Don’t allocate array on no args
This commit is contained in:
Richard Schneeman 2018-09-07 22:05:23 -04:00 committed by GitHub
commit 273e73dbcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View file

@ -18,9 +18,12 @@ module ActionView
# * <tt>name</tt> - Template name
# * <tt>finder</tt> - An instance of <tt>ActionView::LookupContext</tt>
# * <tt>dependencies</tt> - An array of dependent views
def digest(name:, finder:, dependencies: [])
dependencies ||= []
cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".")
def digest(name:, finder:, dependencies: nil)
if dependencies.nil? || dependencies.empty?
cache_key = "#{name}.#{finder.rendered_format}"
else
cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".")
end
# this is a correctly done double-checked locking idiom
# (Concurrent::Map's lookups have volatile semantics)
@ -30,7 +33,7 @@ module ActionView
root = tree(name, finder, partial)
dependencies.each do |injected_dep|
root.children << Injected.new(injected_dep, nil, nil)
end
end if dependencies
finder.digest_cache[cache_key] = root.digest(finder)
end
end

View file

@ -19,5 +19,5 @@ class RelationCacheTest < ActionView::TestCase
assert_equal "Hello World", controller.cache_store.read("views/path/projects-#{Project.count}")
end
def view_cache_dependencies; end
def view_cache_dependencies; []; end
end

View file

@ -10,7 +10,7 @@ module RenderTestCases
def setup_view(paths)
@assigns = { secret: "in the sauce" }
@view = Class.new(ActionView::Base) do
def view_cache_dependencies; end
def view_cache_dependencies; []; end
def combined_fragment_cache_key(key)
[ :views, key ]