The file watcher knows which files exist, so don't use slow File.exists?
Possible solution for #903
This commit is contained in:
parent
fc37ef9b99
commit
c9d151ba66
|
@ -56,6 +56,7 @@ module Middleman
|
||||||
class API
|
class API
|
||||||
|
|
||||||
attr_reader :app
|
attr_reader :app
|
||||||
|
attr_reader :known_paths
|
||||||
delegate :logger, :to => :app
|
delegate :logger, :to => :app
|
||||||
|
|
||||||
# Initialize api and internal path cache
|
# Initialize api and internal path cache
|
||||||
|
@ -142,6 +143,12 @@ module Middleman
|
||||||
reload_path(path, true)
|
reload_path(path, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exists?(path)
|
||||||
|
p = Pathname(path)
|
||||||
|
p = p.relative_path_from(Pathname(@app.root)) if !p.relative?
|
||||||
|
@known_paths.include?(p)
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
# Whether this path is ignored
|
# Whether this path is ignored
|
||||||
# @param [Pathname] path
|
# @param [Pathname] path
|
||||||
|
|
|
@ -59,9 +59,9 @@ module Middleman::CoreExtensions
|
||||||
@cache[p] ||= begin
|
@cache[p] ||= begin
|
||||||
in_file = frontmatter_and_content(p)
|
in_file = frontmatter_and_content(p)
|
||||||
|
|
||||||
|
return in_file unless @app.files.exists?("#{path}.frontmatter")
|
||||||
|
|
||||||
external_file = frontmatter_and_content("#{p}.frontmatter")
|
external_file = frontmatter_and_content("#{p}.frontmatter")
|
||||||
|
|
||||||
return in_file if external_file.nil?
|
|
||||||
|
|
||||||
[
|
[
|
||||||
external_file[0].deep_merge(in_file[0]),
|
external_file[0].deep_merge(in_file[0]),
|
||||||
|
@ -145,8 +145,8 @@ module Middleman::CoreExtensions
|
||||||
path
|
path
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil unless File.exists?(full_path)
|
return nil unless @app.files.exists?(full_path)
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
content = nil
|
content = nil
|
||||||
|
|
||||||
|
|
|
@ -476,7 +476,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
|
|
||||||
# If we found one, return it and the found engine
|
# 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
|
engine = found_path ? File.extname(found_path)[1..-1].to_sym : nil
|
||||||
[ found_path || on_disk_path, engine ]
|
[ found_path || on_disk_path, engine ]
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue