mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add some more caching to the lookup
This commit is contained in:
parent
04d4537cd4
commit
02d9dd9000
3 changed files with 37 additions and 17 deletions
|
@ -15,6 +15,18 @@ module AbstractController
|
||||||
klass._write_layout_method
|
klass._write_layout_method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cache_layout(details)
|
||||||
|
layout = @found_layouts ||= {}
|
||||||
|
values = details.values_at(:formats, :locale)
|
||||||
|
|
||||||
|
# Cache nil
|
||||||
|
if layout.key?(values)
|
||||||
|
return layout[values]
|
||||||
|
else
|
||||||
|
layout[values] = yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Specify the layout to use for this class.
|
# Specify the layout to use for this class.
|
||||||
#
|
#
|
||||||
# If the specified layout is a:
|
# If the specified layout is a:
|
||||||
|
@ -76,10 +88,12 @@ module AbstractController
|
||||||
when nil
|
when nil
|
||||||
self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
|
self.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1
|
||||||
def _layout(details)
|
def _layout(details)
|
||||||
if view_paths.exists?("#{_implied_layout_name}", details, "layouts")
|
self.class.cache_layout(details) do
|
||||||
"#{_implied_layout_name}"
|
if view_paths.exists?("#{_implied_layout_name}", details, "layouts")
|
||||||
else
|
"#{_implied_layout_name}"
|
||||||
super
|
else
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ruby_eval
|
ruby_eval
|
||||||
|
|
|
@ -62,6 +62,10 @@ module ActionView
|
||||||
|
|
||||||
class FileSystemResolver < Resolver
|
class FileSystemResolver < Resolver
|
||||||
|
|
||||||
|
def self.cached_glob
|
||||||
|
@@cached_glob ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(path, options = {})
|
def initialize(path, options = {})
|
||||||
raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
|
raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
|
||||||
super(options)
|
super(options)
|
||||||
|
@ -107,20 +111,22 @@ module ActionView
|
||||||
|
|
||||||
# :api: plugin
|
# :api: plugin
|
||||||
def details_to_glob(name, details, prefix, partial, root)
|
def details_to_glob(name, details, prefix, partial, root)
|
||||||
path = ""
|
self.class.cached_glob[[name, prefix, partial, details, root]] ||= begin
|
||||||
path << "#{prefix}/" unless prefix.empty?
|
path = ""
|
||||||
path << (partial ? "_#{name}" : name)
|
path << "#{prefix}/" unless prefix.empty?
|
||||||
|
path << (partial ? "_#{name}" : name)
|
||||||
|
|
||||||
extensions = ""
|
extensions = ""
|
||||||
[:locales, :formats].each do |k|
|
[:locales, :formats].each do |k|
|
||||||
extensions << if exts = details[k]
|
extensions << if exts = details[k]
|
||||||
'{' + exts.map {|e| ".#{e},"}.join + '}'
|
'{' + exts.map {|e| ".#{e},"}.join + '}'
|
||||||
else
|
else
|
||||||
k == :formats ? formats_glob : ''
|
k == :formats ? formats_glob : ''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
"#{root}#{path}#{extensions}#{handler_glob}"
|
"#{root}#{path}#{extensions}#{handler_glob}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: fix me
|
# TODO: fix me
|
||||||
|
|
|
@ -427,7 +427,7 @@ class RequestTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
|
request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
|
||||||
request.expects(:parameters).at_least_once.returns({})
|
request.expects(:parameters).at_least_once.returns({})
|
||||||
assert_equal with_set(Mime::XML, Mime::HTML), request.formats
|
assert_equal with_set(Mime::XML, Mime::HTML, Mime::ALL), request.formats
|
||||||
end
|
end
|
||||||
|
|
||||||
with_accept_header false do
|
with_accept_header false do
|
||||||
|
@ -460,7 +460,7 @@ protected
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_set(*args)
|
def with_set(*args)
|
||||||
args + Mime::SET
|
args
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_accept_header(value)
|
def with_accept_header(value)
|
||||||
|
|
Loading…
Reference in a new issue