Splay refresh interval for stories, fix update_at calculation
This commit is contained in:
parent
fd69b25929
commit
899f8c6fbc
3 changed files with 16 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'fimfiction/client'
|
require_relative 'client'
|
||||||
|
|
||||||
module FicTracker::Backends::FIMFiction
|
module FicTracker::Backends::FIMFiction
|
||||||
class Backend < FicTracker::Backend
|
class Backend < FicTracker::Backend
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ class FicTracker::Cli::Story < Thor
|
||||||
setup!
|
setup!
|
||||||
info = [['Story', 'Chapters', 'Completed', 'Last Updated'], ['-----','--------','---------','------------']]
|
info = [['Story', 'Chapters', 'Completed', 'Last Updated'], ['-----','--------','---------','------------']]
|
||||||
FicTracker::Models::Story.order_by(:name).each do |story|
|
FicTracker::Models::Story.order_by(:name).each do |story|
|
||||||
info << [story.name, story.chapters.size, story.completed?, story.updated_at || story.published_at]
|
info << [story.name, story.chapters.size, story.completed?, (story.updated_at || story.published_at).strftime("%F")]
|
||||||
end
|
end
|
||||||
print_table info
|
print_table info
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ require_relative 'light/tag'
|
||||||
|
|
||||||
module FicTracker::Models
|
module FicTracker::Models
|
||||||
class Story < Sequel::Model
|
class Story < Sequel::Model
|
||||||
# 1/week
|
# 2 weeks
|
||||||
METADATA_REFRESH_INTERVAL = 7 * 24 * 60 * 60
|
METADATA_REFRESH_INTERVAL = 2 * 7 * 24 * 60 * 60
|
||||||
# 6/day
|
# 2/day
|
||||||
CONTENT_REFRESH_INTERVAL = 4 * 60 * 60
|
CONTENT_REFRESH_INTERVAL = 12 * 60 * 60
|
||||||
# 2 months
|
# 2 months
|
||||||
STORY_EXPIRY = 2 * 30 * 24 * 60 * 60
|
STORY_EXPIRY = 2 * 30 * 24 * 60 * 60
|
||||||
|
|
||||||
|
|
@ -115,12 +115,13 @@ module FicTracker::Models
|
||||||
chapter = self.chapters.find { |c| c.slug == entry[:slug] }
|
chapter = self.chapters.find { |c| c.slug == entry[:slug] }
|
||||||
|
|
||||||
if chapter
|
if chapter
|
||||||
latest_chapter_at = [chapter.published_at || Time.at(0), latest_chapter_at].max
|
|
||||||
chapter.set(**entry)
|
chapter.set(**entry)
|
||||||
else
|
else
|
||||||
chapter = FicTracker::Models::Chapter.new(**entry)
|
chapter = FicTracker::Models::Chapter.new(**entry)
|
||||||
to_add << chapter if id
|
to_add << chapter if id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
latest_chapter_at = [chapter.published_at || Time.at(0), latest_chapter_at].max
|
||||||
to_keep << chapter unless id
|
to_keep << chapter unless id
|
||||||
to_remove.delete chapter.id
|
to_remove.delete chapter.id
|
||||||
end
|
end
|
||||||
|
|
@ -177,6 +178,8 @@ module FicTracker::Models
|
||||||
logger.debug "#{self} - Ensuring all chapters are loaded"
|
logger.debug "#{self} - Ensuring all chapters are loaded"
|
||||||
chapters.each(&:content)
|
chapters.each(&:content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
apply_splay!
|
||||||
end
|
end
|
||||||
|
|
||||||
def ensure_chapters
|
def ensure_chapters
|
||||||
|
|
@ -203,7 +206,7 @@ module FicTracker::Models
|
||||||
end
|
end
|
||||||
|
|
||||||
def safe_name
|
def safe_name
|
||||||
[backend_name, slug, name].join('_').downcase.gsub(/[^a-z0-9\-_]/, '_').gsub(/__+/, '_').gsub(/(^_|_$)/, '')
|
[backend_name, slug, name].join('_').downcase.gsub(/[^[[:alnum:]]-_]/, '_').gsub(/__+/, '_').gsub(/^_|_$/, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh_metadata
|
def refresh_metadata
|
||||||
|
|
@ -226,6 +229,11 @@ module FicTracker::Models
|
||||||
# chapters.each(&:refresh_content!)
|
# chapters.each(&:refresh_content!)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def apply_splay!(max: 1 * 60 * 60)
|
||||||
|
self.last_metadata_refresh += rand(0..max)
|
||||||
|
self.last_content_refresh += rand(0..max)
|
||||||
|
end
|
||||||
|
|
||||||
def needs_metadata_refresh?
|
def needs_metadata_refresh?
|
||||||
# return true if id && authors.empty?
|
# return true if id && authors.empty?
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue