The file watcher knows which files exist, so don't use slow File.exists?

Possible solution for #903
This commit is contained in:
Thomas Reynolds 2013-05-22 17:37:43 -07:00
parent fc37ef9b99
commit c9d151ba66
3 changed files with 12 additions and 5 deletions

View file

@ -56,6 +56,7 @@ module Middleman
class API
attr_reader :app
attr_reader :known_paths
delegate :logger, :to => :app
# Initialize api and internal path cache
@ -142,6 +143,12 @@ module Middleman
reload_path(path, true)
end
def exists?(path)
p = Pathname(path)
p = p.relative_path_from(Pathname(@app.root)) if !p.relative?
@known_paths.include?(p)
end
protected
# Whether this path is ignored
# @param [Pathname] path

View file

@ -59,9 +59,9 @@ module Middleman::CoreExtensions
@cache[p] ||= begin
in_file = frontmatter_and_content(p)
return in_file unless @app.files.exists?("#{path}.frontmatter")
external_file = frontmatter_and_content("#{p}.frontmatter")
return in_file if external_file.nil?
[
external_file[0].deep_merge(in_file[0]),
@ -145,8 +145,8 @@ module Middleman::CoreExtensions
path
end
return nil unless File.exists?(full_path)
return nil unless @app.files.exists?(full_path)
data = {}
content = nil

View file

@ -476,7 +476,7 @@ module Middleman
end
# If we found one, return it and the found engine
if found_path || (File.exists?(on_disk_path) && !File.directory?(on_disk_path))
if found_path || files.exists?(on_disk_path)
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
[ found_path || on_disk_path, engine ]
else