Invalidate sort result cache after change sort_title

This commit is contained in:
Leeingnyo 2021-12-25 22:12:09 +09:00
parent 45ffa3d428
commit edfef80e5c
3 changed files with 22 additions and 4 deletions

View File

@ -81,9 +81,17 @@ class Entry
@title
end
def sort_title=(sort_title : String | Nil)
def set_sort_title(sort_title : String | Nil, username : String)
Storage.default.set_entry_sort_title id, sort_title
@sort_title = sort_title
[false, true].each do |ascend|
[SortMethod::Auto, SortMethod::Title].each do |sort_method|
sorted_entries_cache_key = SortedEntriesCacheEntry.gen_key @book.id,
username, @book.entries, SortOptions.new(sort_method, ascend)
LRUCache.invalidate sorted_entries_cache_key
end
end
end
def sort_title_db

View File

@ -300,9 +300,18 @@ class Title
@title
end
def sort_title=(sort_title : String | Nil)
def set_sort_title(sort_title : String | Nil, username : String)
Storage.default.set_title_sort_title id, sort_title
@sort_title = sort_title
[false, true].each do |ascend|
[SortMethod::Auto, SortMethod::Title].each do |sort_method|
sorted_entries_cache_key =
SortedEntriesCacheEntry.gen_key @id, username, @entries,
SortOptions.new(sort_method, ascend)
LRUCache.invalidate sorted_entries_cache_key
end
end
end
def sort_title_db

View File

@ -380,16 +380,17 @@ struct APIRouter
Koa.query "name", desc: "The new sort title"
Koa.response 200, schema: "result"
put "/api/admin/sort_title/:tid" do |env|
username = get_username env
begin
title = (Library.default.get_title env.params.url["tid"])
.not_nil!
name = env.params.query["name"]?
entry = env.params.query["eid"]?
if entry.nil?
title.sort_title = name
title.set_sort_title name, username
else
eobj = title.get_entry entry
eobj.sort_title = name unless eobj.nil?
eobj.set_sort_title name, username unless eobj.nil?
end
rescue e
Logger.error e