mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
6d11711042
commit
997c76cf80
4 changed files with 10 additions and 25 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
[]
|
||||
|
|
|
@ -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:0x[0-9a-f]+ @cache=#<ActionView::Resolver::Cache:0x[0-9a-f]+ keys=0 queries=0>>), ActionView::Resolver.new.inspect
|
||||
assert_match %r(#<ActionView::Resolver:0x[0-9a-f]+ @cache=#<ActionView::Resolver::Cache:0x[0-9a-f]+ keys=0>>), ActionView::Resolver.new.inspect
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue