Improve full story retrieval
This commit is contained in:
parent
61587d6e0c
commit
3a650b1cef
2 changed files with 23 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -170,6 +170,8 @@ module FicTracker::Util
|
|||
end
|
||||
|
||||
def decode_data(data)
|
||||
return unless data
|
||||
|
||||
flags = data[0].unpack('C').first
|
||||
data = data[1..]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue