mirror of
https://github.com/hkalexling/Mango.git
synced 2026-04-25 00:00:52 -04:00
Replace InfoCache to LRUCache
This commit is contained in:
+13
-15
@@ -60,10 +60,6 @@ class Title
|
||||
@entries.sort! do |a, b|
|
||||
sorter.compare a.title, b.title
|
||||
end
|
||||
|
||||
InfoCache.move_cover_url @id
|
||||
InfoCache.move_progress_cache @id
|
||||
InfoCache.move_sort_opt @dir
|
||||
end
|
||||
|
||||
def to_slim_json : String
|
||||
@@ -234,8 +230,8 @@ class Title
|
||||
end
|
||||
|
||||
def cover_url
|
||||
cached_cover_url = InfoCache.get_cover_url @id
|
||||
return cached_cover_url if cached_cover_url
|
||||
cached_cover_url = LRUCache.get "#{@id}:cover_url"
|
||||
return cached_cover_url if cached_cover_url.is_a? String
|
||||
|
||||
url = "#{Config.current.base_url}img/icon.png"
|
||||
readable_entries = @entries.select &.err_msg.nil?
|
||||
@@ -248,12 +244,12 @@ class Title
|
||||
url = File.join Config.current.base_url, info_url
|
||||
end
|
||||
end
|
||||
InfoCache.set_cover_url @id, url
|
||||
LRUCache.set generate_cache_entry "#{@id}:cover_url", url
|
||||
url
|
||||
end
|
||||
|
||||
def set_cover_url(url : String)
|
||||
InfoCache.invalidate_cover_url @id
|
||||
LRUCache.invalidate "#{@id}:cover_url"
|
||||
TitleInfo.new @dir do |info|
|
||||
info.cover_url = url
|
||||
info.save
|
||||
@@ -262,7 +258,7 @@ class Title
|
||||
|
||||
def set_cover_url(entry_name : String, url : String)
|
||||
selected_entry = @entries.find { |entry| entry.display_name == entry_name }
|
||||
InfoCache.invalidate_cover_url selected_entry.id if selected_entry
|
||||
LRUCache.invalidate "#{selected_entry.id}:cover_url" if selected_entry
|
||||
TitleInfo.new @dir do |info|
|
||||
info.entry_cover_url[entry_name] = url
|
||||
info.save
|
||||
@@ -284,12 +280,14 @@ class Title
|
||||
end
|
||||
|
||||
def deep_read_page_count(username) : Int32
|
||||
# CACHE HERE
|
||||
cached_sum = InfoCache.get_progress_cache @id, username, @entries
|
||||
return cached_sum unless cached_sum.nil?
|
||||
key = "#{@id}:#{username}:progress_sum"
|
||||
sig = Digest::SHA1.hexdigest (entries.map &.id).to_s
|
||||
cached_sum = LRUCache.get key
|
||||
return cached_sum[1] if cached_sum.is_a? Tuple(String, Int32) &&
|
||||
cached_sum[0] == sig
|
||||
sum = load_progress_for_all_entries(username).sum +
|
||||
titles.flat_map(&.deep_read_page_count username).sum
|
||||
InfoCache.set_progress_cache @id, username, @entries, sum
|
||||
LRUCache.set generate_cache_entry key, {sig, sum}
|
||||
sum
|
||||
end
|
||||
|
||||
@@ -445,9 +443,9 @@ class Title
|
||||
end
|
||||
|
||||
def bulk_progress(action, ids : Array(String), username)
|
||||
InfoCache.invalidate_progress_cache @id, username
|
||||
LRUCache.invalidate "#{@id}:#{username}:progress_sum"
|
||||
parents.each do |parent|
|
||||
InfoCache.invalidate_progress_cache parent.id, username
|
||||
LRUCache.invalidate "#{parent.id}:#{username}:progress_sum"
|
||||
end
|
||||
[false, true].each do |ascend|
|
||||
sorted_entries_cache_key =
|
||||
|
||||
Reference in New Issue
Block a user