Attempt to optimize query for subscription feed

This commit is contained in:
Omar Roth 2019-07-07 14:00:42 -05:00
parent 775612ec5a
commit c34a24b633
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2
3 changed files with 8 additions and 17 deletions

View file

@ -1282,10 +1282,7 @@ post "/login" do |env|
PG_DB.exec("INSERT INTO session_ids VALUES ($1, $2, $3)", sid, email, Time.utc)
view_name = "subscriptions_#{sha256(user.email)}"
PG_DB.exec("CREATE MATERIALIZED VIEW #{view_name} AS \
SELECT * FROM channel_videos WHERE
ucid IN (SELECT unnest(subscriptions) FROM users WHERE email = E'#{user.email.gsub("'", "\\'")}')
ORDER BY published DESC")
PG_DB.exec("CREATE MATERIALIZED VIEW #{view_name} AS #{MATERIALIZED_VIEW_SQL.call(user.email)}")
if Kemal.config.ssl || config.https_only
secure = true