diff --git a/src/config.cr b/src/config.cr index bc7aa18..99fb5b9 100644 --- a/src/config.cr +++ b/src/config.cr @@ -23,7 +23,6 @@ class Config property cache_enabled = false property cache_size_mbs = 50 property cache_log_enabled = true - property forcely_yield_count = 1000 property disable_login = false property default_username = "" property auth_proxy_header_name = "" diff --git a/src/library/library.cr b/src/library/library.cr index de8d7b4..ce1a8fc 100644 --- a/src/library/library.cr +++ b/src/library/library.cr @@ -133,9 +133,7 @@ class Library storage = Storage.new auto_close: false - count = Config.current.forcely_yield_count examine_context : ExamineContext = { - file_counter: (YieldCounter.new count), cached_contents_signature: {} of String => String, deleted_title_ids: [] of String, deleted_entry_ids: [] of String, diff --git a/src/library/title.cr b/src/library/title.cr index f57024c..6a959d8 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -73,7 +73,7 @@ class Title def examine(context : ExamineContext) : Bool return false unless Dir.exists? @dir # No title, Remove this contents_signature = Dir.contents_signature @dir, - context["cached_contents_signature"], context["file_counter"] + context["cached_contents_signature"] # Not changed. Reuse this return true if @contents_signature == contents_signature @@ -112,7 +112,7 @@ class Title previous_entries_size = @entries.size @entries.select! do |entry| existence = File.exists? entry.zip_path - context["file_counter"].count_and_yield + Fiber.yield context["deleted_entry_ids"] << entry.id unless existence existence end diff --git a/src/library/types.cr b/src/library/types.cr index a0e0428..4c9dc93 100644 --- a/src/library/types.cr +++ b/src/library/types.cr @@ -134,21 +134,7 @@ class TitleInfo end end -class YieldCounter - @file_count : UInt32 - - def initialize(@threshold : Int32) - @file_count = 0 - end - - def count_and_yield - @file_count += 1 - Fiber.yield if @threshold > 0 && @file_count % @threshold == 0 - end -end - alias ExamineContext = NamedTuple( - file_counter: YieldCounter, cached_contents_signature: Hash(String, String), deleted_title_ids: Array(String), deleted_entry_ids: Array(String)) diff --git a/src/util/signature.cr b/src/util/signature.cr index 76e2628..5ca3e14 100644 --- a/src/util/signature.cr +++ b/src/util/signature.cr @@ -54,24 +54,22 @@ 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, - counter : YieldCounter? = nil) : String + def self.contents_signature(dirname, cache = {} of String => String) : String return cache[dirname] if cache[dirname]? - counter.count_and_yield unless counter.nil? + Fiber.yield signatures = [] of String self.open dirname do |dir| dir.entries.sort.each do |fn| next if fn.starts_with? "." path = File.join dirname, fn if File.directory? path - signatures << Dir.contents_signature path, cache, counter + signatures << Dir.contents_signature path, cache else # Only add its signature value to `signatures` when it is a # supported file signatures << fn if is_supported_file fn end - counter.count_and_yield unless counter.nil? + Fiber.yield end end hash = Digest::SHA1.hexdigest(signatures.join)