Merge pull request #381 from bhollis/speedup

Two speedups
This commit is contained in:
Thomas Reynolds 2012-04-24 09:57:19 -07:00
commit 1d583caf40
3 changed files with 10 additions and 20 deletions

View file

@ -61,10 +61,6 @@ module Middleman::Sitemap::Extensions
elsif block_given?
@ignored_callbacks << block
end
if @ignored_callbacks.size > original_callback_size
@app.sitemap.rebuild_resource_list!(:added_ignore_rule)
end
end
# Whether a path is ignored
@ -74,13 +70,6 @@ module Middleman::Sitemap::Extensions
path_clean = ::Middleman::Util.normalize_path(path)
@ignored_callbacks.any? { |b| b.call(path_clean) }
end
# Update the main sitemap resource list
# @return [void]
def manipulate_resource_list(resources)
# No op
resources
end
end
end
end

View file

@ -48,7 +48,9 @@ module Middleman::Sitemap::Extensions
def get_source_file
if proxy?
store.find_resource_by_path(proxied_to).source_file
proxy_resource = store.find_resource_by_path(proxied_to)
raise "Path #{path} proxies to unknown file #{proxied_to}" unless proxy_resource
proxy_resource.source_file
end
end
end
@ -94,4 +96,4 @@ module Middleman::Sitemap::Extensions
end
end
end
end

View file

@ -20,7 +20,7 @@ module Middleman::Sitemap
def initialize(app)
@app = app
@resources = []
@_cached_metadata = {}
@_lookup_cache = { :path => {}, :destination_path => {} }
@resource_list_manipulators = []
@ -29,11 +29,6 @@ module Middleman::Sitemap
# Proxies
register_resource_list_manipulator(:proxies, @app.proxy_manager, false)
# Ignores
register_resource_list_manipulator(:ignores, @app.ignore_manager, false)
rebuild_resource_list!(:after_base_init)
end
# Register a klass which can manipulate the main site map list
@ -127,6 +122,8 @@ module Middleman::Sitemap
else
@_provides_metadata_for_path << [block, matcher, origin]
end
@_cached_metadata = {}
end
@_provides_metadata_for_path
end
@ -135,9 +132,11 @@ module Middleman::Sitemap
# @param [String] request_path
# @return [Hash]
def metadata_for_path(request_path)
return @_cached_metadata[request_path] if @_cached_metadata[request_path]
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
when Regexp
next result unless request_path.match(matcher)