fix: handle channel refresh continuations

This commit is contained in:
Agastya 2026-09-26 10:16:56 +05:30
parent 8118fa612e
commit f76a50ecce
2 changed files with 15 additions and 12 deletions

View File

@ -199,7 +199,7 @@ private def update_all_channel_videos(ucid : String, channel : InvidiousChannel,
videos = items.select(SearchVideo) videos = items.select(SearchVideo)
update_channel_videos(ucid, videos, skip_recent: true) update_channel_videos(ucid, videos, skip_recent: true)
break if videos.size < 25 break if continuation.nil?
sleep 500.milliseconds sleep 500.milliseconds
end end
end end
@ -212,7 +212,7 @@ private def update_all_channel_shorts(ucid : String, channel : AboutChannel, con
videos = items.select(SearchVideo) videos = items.select(SearchVideo)
update_channel_videos(ucid, videos, skip_recent: true) update_channel_videos(ucid, videos, skip_recent: true)
break if videos.size < 25 break if continuation.nil?
sleep 500.milliseconds sleep 500.milliseconds
end end
end end
@ -225,7 +225,7 @@ private def update_all_channel_livestreams(ucid : String, channel : AboutChannel
videos = items.select(SearchVideo) videos = items.select(SearchVideo)
update_channel_videos(ucid, videos, skip_recent: true) update_channel_videos(ucid, videos, skip_recent: true)
break if videos.size < 25 break if continuation.nil?
sleep 500.milliseconds sleep 500.milliseconds
end end
end end
@ -281,17 +281,14 @@ private def fetch_video_published_at(video_id : String) : Time?
return parse_video_published_at(published) return parse_video_published_at(published)
end end
date_text = response.dig?( date_text = response.dig?("contents", "twoColumnWatchNextResults", "results", "results", "contents")
"contents", "twoColumnWatchNextResults", "results", "results", "contents", 0, .try &.as_a.find(&.["videoPrimaryInfoRenderer"]?)
"videoPrimaryInfoRenderer", "dateText", "simpleText" .try &.dig?("videoPrimaryInfoRenderer", "dateText", "simpleText")
).try(&.as_s) .try &.as_s
return date_text.try do |text| return date_text.try do |text|
Time.parse(text.lchop("Scheduled for "), "%b %-d, %Y", Time::Location::UTC) parse_video_published_date(text.lchop("Scheduled for "))
end end
rescue ex
LOGGER.debug("fetch_video_published_at: #{video_id}: #{ex.message}")
return nil
end end
private def parse_video_published_at(published : String) : Time private def parse_video_published_at(published : String) : Time
@ -299,3 +296,9 @@ private def parse_video_published_at(published : String) : Time
rescue rescue
return Time.parse(published, "%Y-%m-%d", Time::Location::UTC) return Time.parse(published, "%Y-%m-%d", Time::Location::UTC)
end end
private def parse_video_published_date(published : String) : Time?
return Time.parse(published, "%b %-d, %Y", Time::Location::UTC)
rescue
return nil
end

View File

@ -108,7 +108,7 @@ module Invidious::Database::ChannelVideos
if preserve_timestamps_on_conflict if preserve_timestamps_on_conflict
published_on_conflict = "published = COALESCE(channel_videos.published, EXCLUDED.published)" published_on_conflict = "published = COALESCE(channel_videos.published, EXCLUDED.published)"
views_on_conflict = "views = CASE WHEN EXCLUDED.views = 0 AND channel_videos.views > 0 THEN channel_videos.views ELSE EXCLUDED.views END" views_on_conflict = "views = CASE WHEN EXCLUDED.views = 0 AND channel_videos.views > 0 THEN channel_videos.views ELSE EXCLUDED.views END"
updated_on_conflict = "updated = CASE WHEN channel_videos.title IS DISTINCT FROM EXCLUDED.title OR channel_videos.ucid IS DISTINCT FROM EXCLUDED.ucid OR channel_videos.author IS DISTINCT FROM EXCLUDED.author OR channel_videos.length_seconds IS DISTINCT FROM EXCLUDED.length_seconds OR channel_videos.live_now IS DISTINCT FROM EXCLUDED.live_now OR channel_videos.views IS DISTINCT FROM CASE WHEN EXCLUDED.views = 0 AND channel_videos.views > 0 THEN channel_videos.views ELSE EXCLUDED.views END THEN EXCLUDED.updated ELSE channel_videos.updated END" updated_on_conflict = "updated = CASE WHEN channel_videos.title IS DISTINCT FROM EXCLUDED.title OR channel_videos.ucid IS DISTINCT FROM EXCLUDED.ucid OR channel_videos.author IS DISTINCT FROM EXCLUDED.author OR channel_videos.length_seconds IS DISTINCT FROM EXCLUDED.length_seconds OR channel_videos.live_now IS DISTINCT FROM EXCLUDED.live_now THEN EXCLUDED.updated ELSE channel_videos.updated END"
else else
published_on_conflict = "published = $3" published_on_conflict = "published = $3"
updated_on_conflict = "updated = $4" updated_on_conflict = "updated = $4"