summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-10-10 16:10:58 -0500
committerOmar Roth <omarroth@hotmail.com>2018-10-10 16:10:58 -0500
commit921c34aa650463de75e3fa0d72b52975a0ea0646 (patch)
tree18fb86617d898830b6fc4f13fba824db534c7ec9
parentccc423f6826b5c1ff25457484b02c716d97ca8b4 (diff)
downloadinvidious-921c34aa650463de75e3fa0d72b52975a0ea0646.tar.gz
invidious-921c34aa650463de75e3fa0d72b52975a0ea0646.tar.bz2
invidious-921c34aa650463de75e3fa0d72b52975a0ea0646.zip
Create materialized views for Google accounts
-rw-r--r--src/invidious/users.cr18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/invidious/users.cr b/src/invidious/users.cr
index 608ca4d7..4116e732 100644
--- a/src/invidious/users.cr
+++ b/src/invidious/users.cr
@@ -119,6 +119,15 @@ def get_user(sid, client, headers, db, refresh = true)
db.exec("INSERT INTO users VALUES (#{args}) \
ON CONFLICT (email) DO UPDATE SET id = users.id || $1, updated = $2, subscriptions = $4", user_array)
+
+ begin
+ view_name = "subscriptions_#{sha256(user.email)[0..7]}"
+ PG_DB.exec("CREATE MATERIALIZED VIEW #{view_name} AS \
+ SELECT * FROM channel_videos WHERE \
+ ucid = ANY ((SELECT subscriptions FROM users WHERE email = '#{user.email}')::text[]) \
+ ORDER BY published DESC;")
+ rescue ex
+ end
end
else
user = fetch_user(sid, client, headers, db)
@@ -129,6 +138,15 @@ def get_user(sid, client, headers, db, refresh = true)
db.exec("INSERT INTO users VALUES (#{args}) \
ON CONFLICT (email) DO UPDATE SET id = users.id || $1, updated = $2, subscriptions = $4", user_array)
+
+ begin
+ view_name = "subscriptions_#{sha256(user.email)[0..7]}"
+ PG_DB.exec("CREATE MATERIALIZED VIEW #{view_name} AS \
+ SELECT * FROM channel_videos WHERE \
+ ucid = ANY ((SELECT subscriptions FROM users WHERE email = '#{user.email}')::text[]) \
+ ORDER BY published DESC;")
+ rescue ex
+ end
end
return user