From 997c76cf80837fa74bb31f12c15eed519c07e388 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Fri, 9 Apr 2021 18:16:18 -0700 Subject: [PATCH] Resolve wildcards depends using all_template_paths This switches wildcard dependencies from using its custom find_all_with_query method to use all_template_paths, the same method now used for DidYouMean template suggestions. This also removes related cache for wildcard queries. Since it was only used during digesting, the digest cache should be sufficient. --- actionview/lib/action_view/dependency_tracker.rb | 10 +++++++--- actionview/lib/action_view/path_set.rb | 9 --------- actionview/lib/action_view/template/resolver.rb | 14 ++------------ actionview/test/template/resolver_cache_test.rb | 2 +- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/actionview/lib/action_view/dependency_tracker.rb b/actionview/lib/action_view/dependency_tracker.rb index bcdee64681..b9749bab84 100644 --- a/actionview/lib/action_view/dependency_tracker.rb +++ b/actionview/lib/action_view/dependency_tracker.rb @@ -159,10 +159,14 @@ module ActionView def resolve_directories(wildcard_dependencies) return [] unless @view_paths + return [] if wildcard_dependencies.empty? - wildcard_dependencies.flat_map { |query, templates| - @view_paths.find_all_with_query(query).map do |template| - "#{File.dirname(query)}/#{File.basename(template).split('.').first}" + # Remove trailing "*" + prefixes = wildcard_dependencies.map { |query| query[0..-2] } + + @view_paths.flat_map(&:all_template_paths).uniq.select { |path| + prefixes.any? do |prefix| + path.start_with?(prefix) && !path.index("/", prefix.size) end }.sort end diff --git a/actionview/lib/action_view/path_set.rb b/actionview/lib/action_view/path_set.rb index 6044754a3e..377963a35b 100644 --- a/actionview/lib/action_view/path_set.rb +++ b/actionview/lib/action_view/path_set.rb @@ -56,15 +56,6 @@ module ActionView #:nodoc: find_all(path, prefixes, *args).any? end - def find_all_with_query(query) # :nodoc: - paths.each do |resolver| - templates = resolver.find_all_with_query(query) - return templates unless templates.empty? - end - - [] - end - private def _find_all(path, prefixes, args) prefixes = [prefixes] if String === prefixes diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index bdb33c0ed5..6d01614084 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -89,11 +89,10 @@ module ActionView def initialize @data = SmallCache.new(&KEY_BLOCK) - @query_cache = SmallCache.new end def inspect - "#{to_s[0..-2]} keys=#{@data.size} queries=#{@query_cache.size}>" + "#{to_s[0..-2]} keys=#{@data.size}>" end # Cache the templates returned by the block @@ -101,13 +100,8 @@ module ActionView @data[key][name][prefix][partial][locals] ||= canonical_no_templates(yield) end - def cache_query(query) # :nodoc: - @query_cache[query] ||= canonical_no_templates(yield) - end - def clear @data.clear - @query_cache.clear end # Get the cache size. Do not call this @@ -124,7 +118,7 @@ module ActionView end end - size + @query_cache.size + size end private @@ -156,10 +150,6 @@ module ActionView end end - def find_all_with_query(query) # :nodoc: - @cache.cache_query(query) { find_template_paths(File.join(@path, query)) } - end - def all_template_paths # :nodoc: # Not implemented by default [] diff --git a/actionview/test/template/resolver_cache_test.rb b/actionview/test/template/resolver_cache_test.rb index 90b61a2aa1..625bf653dd 100644 --- a/actionview/test/template/resolver_cache_test.rb +++ b/actionview/test/template/resolver_cache_test.rb @@ -5,6 +5,6 @@ require "abstract_unit" class ResolverCacheTest < ActiveSupport::TestCase def test_inspect_shields_cache_internals ActionView::LookupContext::DetailsKey.clear - assert_match %r(#>), ActionView::Resolver.new.inspect + assert_match %r(#>), ActionView::Resolver.new.inspect end end