diff --git a/src/library/title.cr b/src/library/title.cr index 8260be9..2e9db26 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -70,11 +70,12 @@ class Title end end - def examine : Bool + def examine(cache = {} of String => String) : Bool return false unless Dir.exists? @dir # no title, should be removed - contents_signature = Dir.contents_signature @dir + contents_signature = Dir.contents_signature @dir, cache # not changed, preserve return true if @contents_signature == contents_signature + puts "Contents changed in #{@dir}" # fix title @contents_signature = contents_signature @@ -95,7 +96,7 @@ class Title previous_titles_size = @title_ids.size @title_ids.select! do |title_id| title = Library.default.get_title! title_id - title.examine + title.examine cache end remained_title_dirs = @title_ids.map do |id| title = Library.default.get_title! id diff --git a/src/util/signature.cr b/src/util/signature.cr index f2bf103..e56aa06 100644 --- a/src/util/signature.cr +++ b/src/util/signature.cr @@ -54,7 +54,8 @@ class Dir # Rescan conditions: # - When a file added, moved, removed, renamed (including which in nested # directories) - def self.contents_signature(dirname) : String + def self.contents_signature(dirname, cache = {} of String => String) : String + return cache[dirname] if cache[dirname]? signatures = [] of String self.open dirname do |dir| dir.entries.sort.each do |fn| @@ -69,6 +70,8 @@ class Dir end end end - Digest::SHA1.hexdigest(signatures.sort.join) + hash = Digest::SHA1.hexdigest(signatures.sort.join) + cache[dirname] = hash + hash end end