Implement sorted entries cache

sorted_entries cached
This commit is contained in:
Leeingnyo
2021-08-22 23:51:23 +09:00
parent 4a09aee177
commit bf81a4e48b
4 changed files with 107 additions and 0 deletions
+11
View File
@@ -344,6 +344,10 @@ class Title
# use the default (auto, ascending)
# When `opt` is not nil, it saves the options to info.json
def sorted_entries(username, opt : SortOptions? = nil)
cache_key = SortedEntriesCache.gen_key @id, username, @entries, opt
cached_entries = SortedEntriesCache.get cache_key
return cached_entries if cached_entries
if opt.nil?
opt = SortOptions.from_info_json @dir, username
end
@@ -377,6 +381,7 @@ class Title
ary.reverse! unless opt.not_nil!.ascend
SortedEntriesCache.set cache_key, ary
ary
end
@@ -442,6 +447,12 @@ class Title
parents.each do |parent|
InfoCache.invalidate_progress_cache parent.id, username
end
[false, true].each do |ascend|
sorted_entries_cache_key =
SortedEntriesCache.gen_key @id, username, @entries,
SortOptions.new(SortMethod::Progress, ascend)
SortedEntriesCache.invalidate sorted_entries_cache_key
end
selected_entries = ids
.map { |id|