mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 02:45:29 -04:00
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:
parent
44a6f822cd
commit
70ab198a33
@ -23,6 +23,7 @@ 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 = ""
|
||||
|
@ -133,8 +133,9 @@ class Library
|
||||
|
||||
storage = Storage.new auto_close: false
|
||||
|
||||
count = Config.current.forcely_yield_count
|
||||
examine_context : ExamineContext = {
|
||||
file_counter: (YieldCounter.new 1000),
|
||||
file_counter: (YieldCounter.new count),
|
||||
cached_contents_signature: {} of String => String,
|
||||
deleted_title_ids: [] of String,
|
||||
deleted_entry_ids: [] of String,
|
||||
|
@ -19,7 +19,7 @@ class Title
|
||||
@[YAML::Field(ignore: true)]
|
||||
@cached_cover_url : String?
|
||||
|
||||
def initialize(@dir : String, @parent_id, cache : Hash(String, String)? = nil)
|
||||
def initialize(@dir : String, @parent_id, cache = {} of String => String)
|
||||
storage = Storage.default
|
||||
@signature = Dir.signature dir
|
||||
id = storage.get_title_id dir, signature
|
||||
@ -43,7 +43,7 @@ class Title
|
||||
next if fn.starts_with? "."
|
||||
path = File.join dir, fn
|
||||
if File.directory? path
|
||||
title = Title.new path, @id
|
||||
title = Title.new path, @id, cache
|
||||
next if title.entries.size == 0 && title.titles.size == 0
|
||||
Library.default.title_hash[title.id] = title
|
||||
@title_ids << title.id
|
||||
@ -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["cached_contents_signature"], context["file_counter"]
|
||||
# Not changed. Reuse this
|
||||
return true if @contents_signature == contents_signature
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user