summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2019-02-27 09:10:28 -0600
committerOmar Roth <omarroth@hotmail.com>2019-02-27 09:10:28 -0600
commit4865529fed65ac1a56bd4e36859828fcce314183 (patch)
treeab6648afade717cfdcb020b58dec7de9ec768e06 /src
parent0a404cc9a6d2453a4d9090c6630e7a3820c80f29 (diff)
downloadinvidious-4865529fed65ac1a56bd4e36859828fcce314183.tar.gz
invidious-4865529fed65ac1a56bd4e36859828fcce314183.tar.bz2
invidious-4865529fed65ac1a56bd4e36859828fcce314183.zip
Create views if they don't exist
Diffstat (limited to 'src')
-rw-r--r--src/invidious/jobs.cr11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/invidious/jobs.cr b/src/invidious/jobs.cr
index 721edd54..dd782727 100644
--- a/src/invidious/jobs.cr
+++ b/src/invidious/jobs.cr
@@ -131,7 +131,16 @@ def refresh_feeds(db, logger, max_threads = 1)
begin
db.exec("REFRESH MATERIALIZED VIEW #{view_name}")
rescue ex
- logger.write("REFRESH #{email} : #{ex.message}\n")
+ # Create view if it doesn't exist
+ if ex.message.try &.ends_with? "does not exist"
+ PG_DB.exec("CREATE MATERIALIZED VIEW #{view_name} AS \
+ SELECT * FROM channel_videos WHERE \
+ ucid = ANY ((SELECT subscriptions FROM users WHERE email = E'#{email.gsub("'", "\\'")}')::text[]) \
+ ORDER BY published DESC;")
+ logger.write("CREATE #{view_name}")
+ else
+ logger.write("REFRESH #{email} : #{ex.message}\n")
+ end
end
active_channel.send(true)