Add config 'forcely_yield_count'

the default value 1000 would make a fiber yield on each 4ms on SSD

Apply yield counter in Dir.contents_signauture
Use contents_signature cache in Title.new
This commit is contained in:
Leeingnyo
2021-09-16 00:16:26 +09:00
parent 44a6f822cd
commit 70ab198a33
4 changed files with 13 additions and 8 deletions
+7 -4
View File
@@ -54,9 +54,11 @@ class Dir
# Rescan conditions:
# - When a file added, moved, removed, renamed (including which in nested
# directories)
def self.contents_signature(dirname, cache = {} of String => String) : String
return cache[dirname] if !cache.nil? && cache[dirname]?
Fiber.yield # Yield first
def self.contents_signature(dirname,
cache = {} of String => String,
counter : YieldCounter? = nil) : String
return cache[dirname] if cache[dirname]?
counter.count_and_yield unless counter.nil?
signatures = [] of String
self.open dirname do |dir|
dir.entries.sort.each do |fn|
@@ -69,10 +71,11 @@ class Dir
# supported file
signatures << fn if is_supported_file fn
end
counter.count_and_yield unless counter.nil?
end
end
hash = Digest::SHA1.hexdigest(signatures.join)
cache[dirname] = hash unless cache.nil?
cache[dirname] = hash
hash
end
end