Cache entries' cover_url

This commit is contained in:
Leeingnyo 2021-08-30 08:13:50 +09:00
parent 8d84a3c502
commit 244f97a68e
2 changed files with 14 additions and 3 deletions

View File

@ -81,9 +81,17 @@ class Entry
def cover_url
return "#{Config.current.base_url}img/icon.png" if @err_msg
unless @book.entry_cover_url_cache
TitleInfo.new @book.dir do |info|
@book.entry_cover_url_cache = info.entry_cover_url
end
end
entry_cover_url = @book.entry_cover_url_cache
url = "#{Config.current.base_url}api/cover/#{@book.id}/#{@id}"
TitleInfo.new @book.dir do |info|
info_url = info.entry_cover_url[@title]?
if entry_cover_url
info_url = entry_cover_url[@title]?
unless info_url.nil? || info_url.empty?
url = File.join Config.current.base_url, info_url
end

View File

@ -3,9 +3,12 @@ require "../archive"
class Title
getter dir : String, parent_id : String, title_ids : Array(String),
entries : Array(Entry), title : String, id : String,
encoded_title : String, mtime : Time, signature : UInt64
encoded_title : String, mtime : Time, signature : UInt64,
entry_cover_url_cache : Hash(String, String)?
setter entry_cover_url_cache : Hash(String, String)?
@entry_display_name_cache : Hash(String, String)?
@entry_cover_url_cache : Hash(String, String)?
def initialize(@dir : String, @parent_id)
storage = Storage.default