diff --git a/src/library/cache.cr b/src/library/cache.cr index 686ae1f..10e4f60 100644 --- a/src/library/cache.cr +++ b/src/library/cache.cr @@ -127,7 +127,8 @@ struct Tuple(*T) end end -alias CacheableType = Array(Entry) | Array(Title) | String | Tuple(String, Int32) +alias CacheableType = Array(Entry) | Array(Title) | String | + Tuple(String, Int32) alias CacheEntryType = SortedEntriesCacheEntry | SortedTitlesCacheEntry | CacheEntry(String, String) | diff --git a/src/library/title.cr b/src/library/title.cr index 8465d56..d5d8692 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -522,7 +522,9 @@ class Title case opt.not_nil!.method when .title? - ary = @entries.sort { |a, b| compare_numerically a.sort_title, b.sort_title } + ary = @entries.sort do |a, b| + compare_numerically a.sort_title, b.sort_title + end when .time_modified? ary = @entries.sort { |a, b| (a.mtime <=> b.mtime).or \ compare_numerically a.sort_title, b.sort_title } diff --git a/src/routes/main.cr b/src/routes/main.cr index 87a7c3b..ea2f0d8 100644 --- a/src/routes/main.cr +++ b/src/routes/main.cr @@ -66,9 +66,9 @@ struct MainRouter percentage = title.load_percentage_for_all_entries username, sort_opt title_percentage = title.titles.map &.load_percentage username title_percentage_map = {} of String => Float64 - title_percentage.each_with_index do |percentage, i| + title_percentage.each_with_index do |tp, i| t = title.titles[i] - title_percentage_map[t.id] = percentage + title_percentage_map[t.id] = tp end layout "title" diff --git a/src/storage.cr b/src/storage.cr index cd3e3c0..4c8cfe7 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -346,7 +346,9 @@ class Storage sort_title = nil MainFiber.run do get_db do |db| - sort_title = db.query_one? "Select sort_title from titles where id = (?)", title_id, as: String | Nil + sort_title = + db.query_one? "Select sort_title from titles where id = (?)", + title_id, as: String | Nil end end sort_title @@ -356,7 +358,8 @@ class Storage sort_title = nil if sort_title == "" MainFiber.run do get_db do |db| - db.exec "update titles set sort_title = (?) where id = (?)", sort_title, title_id + db.exec "update titles set sort_title = (?) where id = (?)", + sort_title, title_id end end end @@ -365,7 +368,9 @@ class Storage sort_title = nil MainFiber.run do get_db do |db| - sort_title = db.query_one? "Select sort_title from ids where id = (?)", entry_id, as: String | Nil + sort_title = + db.query_one? "Select sort_title from ids where id = (?)", + entry_id, as: String | Nil end end sort_title @@ -375,7 +380,8 @@ class Storage results = Hash(String, String | Nil).new MainFiber.run do get_db do |db| - db.query "select id, sort_title from ids where id in (#{ids.join "," { |id| "'#{id}'" }})" do |rs| + db.query "select id, sort_title from ids where id in " \ + "(#{ids.join "," { |id| "'#{id}'" }})" do |rs| rs.each do id = rs.read String sort_title = rs.read String | Nil @@ -391,7 +397,8 @@ class Storage sort_title = nil if sort_title == "" MainFiber.run do get_db do |db| - db.exec "update ids set sort_title = (?) where id = (?)", sort_title, entry_id + db.exec "update ids set sort_title = (?) where id = (?)", + sort_title, entry_id end end end diff --git a/src/util/util.cr b/src/util/util.cr index 74738b7..82edb6a 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -86,7 +86,7 @@ def env_is_true?(key : String) : Bool val.downcase.in? "1", "true" end -def sort_titles(titles : Array(Title), opt : SortOptions, username : String) : Array(Title) +def sort_titles(titles : Array(Title), opt : SortOptions, username : String) cache_key = SortedTitlesCacheEntry.gen_key username, titles, opt cached_titles = LRUCache.get cache_key return cached_titles if cached_titles.is_a? Array(Title)