Permalink
Browse files

Merge pull request #381 from bhollis/speedup

Two speedups
  • Loading branch information...
tdreyno committed Apr 24, 2012
2 parents 163270c + ecf56d8 commit 1d583caf407eb673aa768e79e24d582a31f18d14
@@ -61,10 +61,6 @@ def ignore(path=nil, &block)
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 @@ def ignored?(path)
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
@@ -48,7 +48,9 @@ def template?
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 @@ def manipulate_resource_list(resources)
end
end
-end
+end
@@ -20,7 +20,7 @@ class Store
def initialize(app)
@app = app
@resources = []
-
+ @_cached_metadata = {}
@_lookup_cache = { :path => {}, :destination_path => {} }
@resource_list_manipulators = []
@@ -29,11 +29,6 @@ def initialize(app)
# 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 @@ def provides_metadata_for_path(matcher=nil, origin=nil, &block)
else
@_provides_metadata_for_path << [block, matcher, origin]
end
+
+ @_cached_metadata = {}
end
@_provides_metadata_for_path
end
@@ -135,9 +132,11 @@ def provides_metadata_for_path(matcher=nil, origin=nil, &block)
# @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)

0 comments on commit 1d583ca

Please sign in to comment.