Splay refresh interval for stories, fix update_at calculation

This commit is contained in:
Alexander Olofsson 2024-09-06 00:00:54 +02:00
parent fd69b25929
commit 899f8c6fbc
Signed by: ace
GPG key ID: D439C9470CB04C73
3 changed files with 16 additions and 8 deletions

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require_relative 'fimfiction/client'
require_relative 'client'
module FicTracker::Backends::FIMFiction
class Backend < FicTracker::Backend

View file

@ -71,7 +71,7 @@ class FicTracker::Cli::Story < Thor
setup!
info = [['Story', 'Chapters', 'Completed', 'Last Updated'], ['-----','--------','---------','------------']]
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
print_table info
end

View file

@ -5,10 +5,10 @@ require_relative 'light/tag'
module FicTracker::Models
class Story < Sequel::Model
# 1/week
METADATA_REFRESH_INTERVAL = 7 * 24 * 60 * 60
# 6/day
CONTENT_REFRESH_INTERVAL = 4 * 60 * 60
# 2 weeks
METADATA_REFRESH_INTERVAL = 2 * 7 * 24 * 60 * 60
# 2/day
CONTENT_REFRESH_INTERVAL = 12 * 60 * 60
# 2 months
STORY_EXPIRY = 2 * 30 * 24 * 60 * 60
@ -115,12 +115,13 @@ module FicTracker::Models
chapter = self.chapters.find { |c| c.slug == entry[:slug] }
if chapter
latest_chapter_at = [chapter.published_at || Time.at(0), latest_chapter_at].max
chapter.set(**entry)
else
chapter = FicTracker::Models::Chapter.new(**entry)
to_add << chapter if id
end
latest_chapter_at = [chapter.published_at || Time.at(0), latest_chapter_at].max
to_keep << chapter unless id
to_remove.delete chapter.id
end
@ -177,6 +178,8 @@ module FicTracker::Models
logger.debug "#{self} - Ensuring all chapters are loaded"
chapters.each(&:content)
end
apply_splay!
end
def ensure_chapters
@ -203,7 +206,7 @@ module FicTracker::Models
end
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
def refresh_metadata
@ -226,6 +229,11 @@ module FicTracker::Models
# chapters.each(&:refresh_content!)
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?
# return true if id && authors.empty?