mirror of
https://github.com/hkalexling/Mango.git
synced 2026-05-01 00:00:55 -04:00
Signature matching
This commit is contained in:
@@ -11,13 +11,14 @@ class Entry
|
||||
@title = File.basename @zip_path, File.extname @zip_path
|
||||
@encoded_title = URI.encode @title
|
||||
@size = (File.size @zip_path).humanize_bytes
|
||||
id = storage.get_id @zip_path, false
|
||||
id = storage.get_entry_id @zip_path, File.signature(@zip_path)
|
||||
if id.nil?
|
||||
id = random_str
|
||||
storage.insert_id({
|
||||
path: @zip_path,
|
||||
id: id,
|
||||
is_title: false,
|
||||
path: @zip_path,
|
||||
id: id,
|
||||
title_signature: nil,
|
||||
entry_signature: File.signature(@zip_path).to_s,
|
||||
})
|
||||
end
|
||||
@id = id
|
||||
|
||||
+1
-10
@@ -42,16 +42,6 @@ class Library
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
db_interval = Config.current.db_optimization_interval_hours
|
||||
unless db_interval < 1
|
||||
spawn do
|
||||
loop do
|
||||
Storage.default.optimize
|
||||
sleep db_interval.hours
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def titles
|
||||
@@ -119,6 +109,7 @@ class Library
|
||||
storage.close
|
||||
|
||||
Logger.debug "Scan completed"
|
||||
Storage.default.optimize
|
||||
end
|
||||
|
||||
def get_continue_reading_entries(username)
|
||||
|
||||
+7
-11
@@ -3,19 +3,21 @@ require "../archive"
|
||||
class Title
|
||||
getter dir : String, parent_id : String, title_ids : Array(String),
|
||||
entries : Array(Entry), title : String, id : String,
|
||||
encoded_title : String, mtime : Time, signature : UInt64 = 0
|
||||
encoded_title : String, mtime : Time, signature : UInt64
|
||||
|
||||
@entry_display_name_cache : Hash(String, String)?
|
||||
|
||||
def initialize(@dir : String, @parent_id)
|
||||
storage = Storage.default
|
||||
id = storage.get_id @dir, true
|
||||
@signature = Dir.signature dir
|
||||
id = storage.get_title_id dir, signature
|
||||
if id.nil?
|
||||
id = random_str
|
||||
storage.insert_id({
|
||||
path: @dir,
|
||||
id: id,
|
||||
is_title: true,
|
||||
path: dir,
|
||||
id: id,
|
||||
title_signature: signature.to_s,
|
||||
entry_signature: nil,
|
||||
})
|
||||
end
|
||||
@id = id
|
||||
@@ -25,8 +27,6 @@ class Title
|
||||
@entries = [] of Entry
|
||||
@mtime = File.info(dir).modification_time
|
||||
|
||||
signatures = [] of UInt64
|
||||
|
||||
Dir.entries(dir).each do |fn|
|
||||
next if fn.starts_with? "."
|
||||
path = File.join dir, fn
|
||||
@@ -35,18 +35,14 @@ class Title
|
||||
next if title.entries.size == 0 && title.titles.size == 0
|
||||
Library.default.title_hash[title.id] = title
|
||||
@title_ids << title.id
|
||||
signatures << title.signature
|
||||
next
|
||||
end
|
||||
if [".zip", ".cbz", ".rar", ".cbr"].includes? File.extname path
|
||||
entry = Entry.new path, self
|
||||
@entries << entry if entry.pages > 0 || entry.err_msg
|
||||
signatures << File.size entry.zip_path
|
||||
end
|
||||
end
|
||||
|
||||
@signature = Digest::CRC32.checksum(signatures.sort.join "").to_u64
|
||||
|
||||
mtimes = [@mtime]
|
||||
mtimes += @title_ids.map { |e| Library.default.title_hash[e].mtime }
|
||||
mtimes += @entries.map { |e| e.mtime }
|
||||
|
||||
Reference in New Issue
Block a user