mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Prevent saving a sort opt unnecessarily
This commit is contained in:
parent
51a47b5ddd
commit
00c9cc1fcd
@ -51,11 +51,6 @@ class Library
|
|||||||
def sorted_titles(username, opt : SortOptions? = nil)
|
def sorted_titles(username, opt : SortOptions? = nil)
|
||||||
if opt.nil?
|
if opt.nil?
|
||||||
opt = SortOptions.from_info_json @dir, username
|
opt = SortOptions.from_info_json @dir, username
|
||||||
else
|
|
||||||
TitleInfo.new @dir do |info|
|
|
||||||
info.sort_by[username] = opt.to_tuple
|
|
||||||
info.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Helper function from src/util/util.cr
|
# Helper function from src/util/util.cr
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
require "digest"
|
||||||
require "../archive"
|
require "../archive"
|
||||||
|
|
||||||
class Title
|
class Title
|
||||||
@ -329,11 +330,6 @@ class Title
|
|||||||
def sorted_entries(username, opt : SortOptions? = nil)
|
def sorted_entries(username, opt : SortOptions? = nil)
|
||||||
if opt.nil?
|
if opt.nil?
|
||||||
opt = SortOptions.from_info_json @dir, username
|
opt = SortOptions.from_info_json @dir, username
|
||||||
else
|
|
||||||
TitleInfo.new @dir do |info|
|
|
||||||
info.sort_by[username] = opt.to_tuple
|
|
||||||
info.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
case opt.not_nil!.method
|
case opt.not_nil!.method
|
||||||
|
@ -41,7 +41,7 @@ struct MainRouter
|
|||||||
username = get_username env
|
username = get_username env
|
||||||
|
|
||||||
sort_opt = SortOptions.from_info_json Library.default.dir, username
|
sort_opt = SortOptions.from_info_json Library.default.dir, username
|
||||||
get_sort_opt
|
get_and_save_sort_opt Library.default.dir
|
||||||
|
|
||||||
titles = Library.default.sorted_titles username, sort_opt
|
titles = Library.default.sorted_titles username, sort_opt
|
||||||
percentage = titles.map &.load_percentage username
|
percentage = titles.map &.load_percentage username
|
||||||
@ -59,12 +59,12 @@ struct MainRouter
|
|||||||
username = get_username env
|
username = get_username env
|
||||||
|
|
||||||
sort_opt = SortOptions.from_info_json title.dir, username
|
sort_opt = SortOptions.from_info_json title.dir, username
|
||||||
get_sort_opt
|
get_and_save_sort_opt title.dir
|
||||||
|
|
||||||
entries = title.sorted_entries username, sort_opt
|
entries = title.sorted_entries username, sort_opt
|
||||||
|
|
||||||
percentage = title.load_percentage_for_all_entries username, sort_opt
|
percentage = title.load_percentage_for_all_entries username, sort_opt
|
||||||
title_percentage = title.titles.map &.load_percentage username
|
title_percentage = title.titles.map &.load_percentage username
|
||||||
|
|
||||||
layout "title"
|
layout "title"
|
||||||
rescue e
|
rescue e
|
||||||
Logger.error e
|
Logger.error e
|
||||||
|
@ -107,6 +107,26 @@ macro get_sort_opt
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro get_and_save_sort_opt(dir)
|
||||||
|
sort_method = env.params.query["sort"]?
|
||||||
|
|
||||||
|
if sort_method
|
||||||
|
is_ascending = true
|
||||||
|
|
||||||
|
ascend = env.params.query["ascend"]?
|
||||||
|
if ascend && ascend.to_i? == 0
|
||||||
|
is_ascending = false
|
||||||
|
end
|
||||||
|
|
||||||
|
sort_opt = SortOptions.new sort_method, is_ascending
|
||||||
|
|
||||||
|
TitleInfo.new {{dir}} do |info|
|
||||||
|
info.sort_by[username] = sort_opt.to_tuple
|
||||||
|
info.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module HTTP
|
module HTTP
|
||||||
class Client
|
class Client
|
||||||
private def self.exec(uri : URI, tls : TLSContext = nil)
|
private def self.exec(uri : URI, tls : TLSContext = nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user