Cache the filtered resource list to avoid calling Resource#ignored? a ton

This commit is contained in:
Ben Hollis 2013-05-23 00:11:09 -07:00
parent 950aace674
commit e03ef4226a
2 changed files with 13 additions and 2 deletions

View file

@ -68,11 +68,14 @@ module Middleman
@ignored_callbacks << Proc.new {|p| File.fnmatch(path_clean, p) }
else
# Add a specific-path ignore unless that path is already covered
@ignored_callbacks << Proc.new {|p| p == path_clean } unless ignored?(path_clean)
return if ignored?(path_clean)
@ignored_callbacks << Proc.new {|p| p == path_clean }
end
elsif block_given?
@ignored_callbacks << block
end
@app.sitemap.invalidate_resources_not_ignored_cache!
end
# Whether a path is ignored

View file

@ -90,11 +90,17 @@ module Middleman
if include_ignored
@resources
else
@resources.reject(&:ignored?)
@resources_not_ignored ||= @resources.reject(&:ignored?)
end
end
end
# Invalidate our cached view of resource that are not ingnored. If your extension
# adds ways to ignore files, you should call this to make sure #resources works right.
def invalidate_resources_not_ignored_cache!
@resources_not_ignored = nil
end
# Register a handler to provide metadata on a file path
# @param [Regexp] matcher
# @return [Array<Array<Proc, Regexp>>]
@ -213,6 +219,8 @@ module Middleman
newres
end
invalidate_resources_not_ignored_cache!
end
end