Improve full story retrieval

This commit is contained in:
Alexander Olofsson 2024-07-01 07:52:43 +02:00
parent 61587d6e0c
commit 3a650b1cef
Signed by: ace
GPG key ID: D439C9470CB04C73
2 changed files with 23 additions and 3 deletions

View file

@ -143,8 +143,24 @@ module FicTracker::Models
refresh_content
refresh_metadata
# FIXME: Should check for a reasonable set of parameters - full load unless XX% (75%?) of chapters have content
backend.load_full_story(self) unless chapters && chapters.any? && chapters.all? { |c| c.content? && c.content_type? }
full_load = true
if chapters && chapters.size > 0
chapter_count = chapters.size
chapter_loaded = chapters.count { |c| c.content? && c.content_type? }
logger.debug "#{self} - Loaded chapters: #{chapter_loaded}/#{chapter_count}"
# Full load if more than two chapters are not loaded
full_load = (chapter_count - chapter_loaded) > 2
end
if full_load
logger.debug "#{self} - Performing full load"
backend.load_full_story(self)
else
logger.debug "#{self} - Ensuring all chapters are loaded"
chapters.each(&:content)
end
end
def ensure_chapters
@ -179,6 +195,7 @@ module FicTracker::Models
end
def refresh_metadata!
logger.debug "#{self} - Updating metadata"
backend.load_story(self)
end
@ -188,12 +205,13 @@ module FicTracker::Models
end
def refresh_content!
logger.debug "#{self} - Updating chapter list"
backend.find_chapters(self)
# chapters.each(&:refresh_content!)
end
def needs_metadata_refresh?
return true if id && authors.empty?
# return true if id && authors.empty?
Time.now - (last_metadata_refresh || Time.at(0)) >= METADATA_REFRESH_INTERVAL
end

View file

@ -170,6 +170,8 @@ module FicTracker::Util
end
def decode_data(data)
return unless data
flags = data[0].unpack('C').first
data = data[1..]