mirror of
https://github.com/hkalexling/Mango.git
synced 2026-05-01 00:00:55 -04:00
Merge branch 'feature/preserve-scanned-titles' of https://github.com/Leeingnyo/Mango into feature/preserve-scanned-titles
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -82,7 +82,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"]
|
||||
return true if @contents_signature == contents_signature
|
||||
|
||||
@contents_signature = contents_signature
|
||||
@@ -119,7 +119,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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user