Differentiate polling from find_new_files to remove double reads in build mode

This commit is contained in:
Thomas Reynolds 2016-01-20 12:20:27 -08:00
parent ffa662a917
commit 6d1c3562a7
4 changed files with 28 additions and 6 deletions

View file

@ -47,7 +47,7 @@ module Middleman
# @return [void]
Contract Any
def before_configuration
@sources.find_new_files!
@sources.poll_once!
end
# After we config, find new files since config can change paths.
@ -60,7 +60,7 @@ module Middleman
end
@sources.start!
@sources.find_new_files!
@sources.poll_once!
end
protected

View file

@ -91,7 +91,7 @@ module Middleman
validator: (block_given? ? block : regex))
bump_count
find_new_files! if @running
poll_once! if @running
end
# Whether this path is ignored.
@ -219,13 +219,24 @@ module Middleman
.find { |d| d.exists?(path) }
end
# Manually poll all watchers for new content.
# Manually check for new files
#
# @return [void]
Contract ArrayOf[Pathname]
def find_new_files!
return [] unless @update_count != @last_update_count
@last_update_count = @update_count
watchers.reduce([]) { |sum, w| sum + w.find_new_files! }
end
# Manually poll all watchers for new content.
#
# @return [void]
Contract ArrayOf[Pathname]
def poll_once!
return [] unless @update_count != @last_update_count
@last_update_count = @update_count
watchers.reduce([]) { |sum, w| sum + w.poll_once! }
end

View file

@ -1,6 +1,7 @@
# Watcher Library
require 'listen'
require 'middleman-core/contracts'
require 'digest'
# Monkey patch Listen silencer so `only` works on directories too
module Listen
@ -177,6 +178,16 @@ module Middleman
@listener = nil
end
Contract ArrayOf[Pathname]
def find_new_files!
new_files = ::Middleman::Util.all_files_under(@directory.to_s)
.reject { |p| @files.key?(p) }
update(new_files, [])
new_files
end
# Manually trigger update events.
#
# @return [void]

View file

@ -31,13 +31,13 @@ end
Then /^the file "([^\"]*)" has the contents$/ do |path, contents|
write_file(path, contents)
@server_inst.files.find_new_files!
@server_inst.files.poll_once!
end
Then /^the file "([^\"]*)" is removed$/ do |path|
step %Q{I remove the file "#{path}"}
@server_inst.files.find_new_files!
@server_inst.files.poll_once!
end
Given /^a modification time for a file named "([^\"]*)"$/ do |file|