Cache Resource#metadata
This commit is contained in:
parent
35037957a6
commit
ecf56d8e55
|
@ -20,7 +20,7 @@ module Middleman::Sitemap
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
@app = app
|
@app = app
|
||||||
@resources = []
|
@resources = []
|
||||||
|
@_cached_metadata = {}
|
||||||
@_lookup_cache = { :path => {}, :destination_path => {} }
|
@_lookup_cache = { :path => {}, :destination_path => {} }
|
||||||
@resource_list_manipulators = []
|
@resource_list_manipulators = []
|
||||||
|
|
||||||
|
@ -123,6 +123,8 @@ module Middleman::Sitemap
|
||||||
else
|
else
|
||||||
@_provides_metadata_for_path << [block, matcher, origin]
|
@_provides_metadata_for_path << [block, matcher, origin]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@_cached_metadata = {}
|
||||||
end
|
end
|
||||||
@_provides_metadata_for_path
|
@_provides_metadata_for_path
|
||||||
end
|
end
|
||||||
|
@ -131,9 +133,11 @@ module Middleman::Sitemap
|
||||||
# @param [String] request_path
|
# @param [String] request_path
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def metadata_for_path(request_path)
|
def metadata_for_path(request_path)
|
||||||
|
return @_cached_metadata[request_path] if @_cached_metadata[request_path]
|
||||||
|
|
||||||
blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
blank_metadata = { :options => {}, :locals => {}, :page => {}, :blocks => [] }
|
||||||
|
|
||||||
provides_metadata_for_path.inject(blank_metadata) do |result, (callback, matcher)|
|
@_cached_metadata[request_path] = provides_metadata_for_path.inject(blank_metadata) do |result, (callback, matcher)|
|
||||||
case matcher
|
case matcher
|
||||||
when Regexp
|
when Regexp
|
||||||
next result unless request_path.match(matcher)
|
next result unless request_path.match(matcher)
|
||||||
|
|
Loading…
Reference in a new issue