mirror of
https://github.com/hkalexling/Mango.git
synced 2026-04-03 00:03:14 -04:00
Fix title sort bug, invalidate titles of the Library
Refactor remove cache
This commit is contained in:
@@ -91,25 +91,25 @@ def sort_titles(titles : Array(Title), opt : SortOptions, username : String)
|
||||
cached_titles = LRUCache.get cache_key
|
||||
return cached_titles if cached_titles.is_a? Array(Title)
|
||||
|
||||
ary = titles
|
||||
|
||||
case opt.method
|
||||
when .time_modified?
|
||||
ary.sort { |a, b| (a.mtime <=> b.mtime).or \
|
||||
ary = titles.sort { |a, b| (a.mtime <=> b.mtime).or \
|
||||
compare_numerically a.sort_title, b.sort_title }
|
||||
when .progress?
|
||||
ary.sort do |a, b|
|
||||
ary = titles.sort do |a, b|
|
||||
(a.load_percentage(username) <=> b.load_percentage(username)).or \
|
||||
compare_numerically a.sort_title, b.sort_title
|
||||
end
|
||||
when .title?
|
||||
ary.sort { |a, b| compare_numerically a.sort_title, b.sort_title }
|
||||
ary = titles.sort do |a, b|
|
||||
compare_numerically a.sort_title, b.sort_title
|
||||
end
|
||||
else
|
||||
unless opt.method.auto?
|
||||
Logger.warn "Unknown sorting method #{opt.not_nil!.method}. Using " \
|
||||
"Auto instead"
|
||||
end
|
||||
ary.sort { |a, b| compare_numerically a.sort_title, b.sort_title }
|
||||
ary = titles.sort { |a, b| compare_numerically a.sort_title, b.sort_title }
|
||||
end
|
||||
|
||||
ary.reverse! unless opt.not_nil!.ascend
|
||||
@@ -118,6 +118,18 @@ def sort_titles(titles : Array(Title), opt : SortOptions, username : String)
|
||||
ary
|
||||
end
|
||||
|
||||
def remove_sorted_titles_cache(titles : Array(Title),
|
||||
sort_methods : Array(SortMethod),
|
||||
username : String)
|
||||
[false, true].each do |ascend|
|
||||
sort_methods.each do |sort_method|
|
||||
sorted_titles_cache_key = SortedTitlesCacheEntry.gen_key username,
|
||||
titles, SortOptions.new(sort_method, ascend)
|
||||
LRUCache.invalidate sorted_titles_cache_key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class String
|
||||
# Returns the similarity (in [0, 1]) of two paths.
|
||||
# For the two paths, separate them into arrays of components, count the
|
||||
|
||||
Reference in New Issue
Block a user