Improve story retrieval
This commit is contained in:
parent
3682572001
commit
aa0eaaa40a
5 changed files with 40 additions and 19 deletions
0
lib/fic_tracker/models/archive.rb
Normal file
0
lib/fic_tracker/models/archive.rb
Normal file
|
|
@ -158,30 +158,23 @@ module FicTracker::Models
|
|||
refresh_content(splay: true)
|
||||
refresh_metadata(splay: true)
|
||||
|
||||
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}"
|
||||
|
||||
return if chapter_loaded == chapter_count
|
||||
|
||||
# Full load if more than two chapters are not loaded
|
||||
full_load = (chapter_count - chapter_loaded) > 2
|
||||
partial_load_chapters
|
||||
return self
|
||||
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
|
||||
logger.debug "#{self} - Performing full load"
|
||||
backend.load_full_story(self)
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def ensure_chapters
|
||||
ensure_fully_loaded
|
||||
return ensure_fully_loaded unless id
|
||||
return ensure_fully_loaded if chapters.nil? || chapters.size.zero?
|
||||
return ensure_fully_loaded if needs_content_refresh? || needs_metadata_refresh?
|
||||
|
||||
partial_load_chapters
|
||||
end
|
||||
|
||||
def backend
|
||||
|
|
@ -223,7 +216,7 @@ module FicTracker::Models
|
|||
return unless backend && needs_content_refresh?
|
||||
|
||||
self.last_content_refresh += rand(-3600..3600) if splay
|
||||
refresh_content!
|
||||
refresh_content!
|
||||
# chapters.each(&:refresh_content)
|
||||
end
|
||||
|
||||
|
|
@ -279,5 +272,24 @@ module FicTracker::Models
|
|||
def logger
|
||||
Logging.logger[self]
|
||||
end
|
||||
|
||||
def partial_load_chapters
|
||||
chapter_count = chapters.size
|
||||
chapter_loaded = chapters.count { |c| c.content? && c.content_type? }
|
||||
|
||||
return false if chapter_loaded == chapter_count
|
||||
|
||||
full_load = (chapter_count - chapter_loaded) > 2
|
||||
|
||||
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
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ module FicTracker::Renderers
|
|||
def render
|
||||
logger.info "Rendering epub for #{story}"
|
||||
|
||||
story.ensure_chapters
|
||||
story.save_changes if story.id
|
||||
|
||||
require 'zip'
|
||||
require 'zip/filesystem'
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ module FicTracker::Renderers
|
|||
def render
|
||||
logger.info "Rendering html for #{story}"
|
||||
|
||||
story.ensure_chapters
|
||||
story.save_Changes if story.id
|
||||
|
||||
doc = Nokogiri::HTML5::Document.new
|
||||
Nokogiri::XML::Builder.with(doc) do |html|
|
||||
build_html(html) do
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ module FicTracker::Renderers
|
|||
def render
|
||||
logger.info "Rendering markdown for #{story}"
|
||||
|
||||
story.ensure_chapters
|
||||
story.save_changes if story.id
|
||||
|
||||
@io.puts build_preface, nil if preface
|
||||
|
||||
story.chapters.each do |chapter|
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue