From 30e6d291066f489a27b558f536a8ee4f83d79f73 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 9 Feb 2019 10:18:24 -0600 Subject: [PATCH] Add 'deleted' to channel info --- config/migrate-scripts/migrate-db-e1aa1ce.sh | 4 ++++ config/sql/channels.sql | 1 + src/invidious/channels.cr | 3 ++- src/invidious/jobs.cr | 5 ++++- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 config/migrate-scripts/migrate-db-e1aa1ce.sh diff --git a/config/migrate-scripts/migrate-db-e1aa1ce.sh b/config/migrate-scripts/migrate-db-e1aa1ce.sh new file mode 100644 index 00000000..259862df --- /dev/null +++ b/config/migrate-scripts/migrate-db-e1aa1ce.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +psql invidious -c "ALTER TABLE channels ADD COLUMN deleted bool;" +psql invidious -c "UPDATE channels SET deleted = false;" diff --git a/config/sql/channels.sql b/config/sql/channels.sql index c4259c12..cecd04ed 100644 --- a/config/sql/channels.sql +++ b/config/sql/channels.sql @@ -7,6 +7,7 @@ CREATE TABLE public.channels id text NOT NULL, author text, updated timestamp with time zone, + deleted boolean, CONSTRAINT channels_id_key UNIQUE (id) ); diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr index 956450d5..ccaf2487 100644 --- a/src/invidious/channels.cr +++ b/src/invidious/channels.cr @@ -3,6 +3,7 @@ class InvidiousChannel id: String, author: String, updated: Time, + deleted: Bool, }) end @@ -187,7 +188,7 @@ def fetch_channel(ucid, client, db, pull_all_videos = true, locale = nil) db.exec("DELETE FROM channel_videos * WHERE NOT id = ANY ('{#{ids.map { |id| %("#{id}") }.join(",")}}') AND ucid = $1", ucid) end - channel = InvidiousChannel.new(ucid, author, Time.now) + channel = InvidiousChannel.new(ucid, author, Time.now, false) return channel end diff --git a/src/invidious/jobs.cr b/src/invidious/jobs.cr index f6e2d8fe..04816efd 100644 --- a/src/invidious/jobs.cr +++ b/src/invidious/jobs.cr @@ -55,7 +55,7 @@ def refresh_channels(db, logger, max_threads = 1, full_refresh = false) active_channel = Channel(Bool).new loop do - db.query("SELECT id FROM channels ORDER BY updated") do |rs| + db.query("SELECT id FROM channels WHERE deleted = false ORDER BY updated") do |rs| rs.each do id = rs.read(String) @@ -73,6 +73,9 @@ def refresh_channels(db, logger, max_threads = 1, full_refresh = false) db.exec("UPDATE channels SET updated = $1, author = $2 WHERE id = $3", Time.now, channel.author, id) rescue ex + if ex.message == "Deleted or invalid channel" + db.exec("UPDATE channels SET deleted = true WHERE id = $1", id) + end logger.write("#{id} : #{ex.message}\n") end