From 421ad21b40ffaa4e7814a0282ed8aa4ce30de441 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 17 Feb 2019 19:53:42 -0600 Subject: [PATCH] Speed up filtering watched videos from feed --- src/invidious.cr | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 222b82ae..565ae1ae 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1819,15 +1819,9 @@ get "/feed/subscriptions" do |env| else if preferences.latest_only if preferences.unseen_only - if user.watched.empty? - watched = "'{}'" - else - watched = arg_array(user.watched) - end - videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE \ - id NOT IN (#{watched}) ORDER BY ucid, published #{sort}", - user.watched, as: ChannelVideo) + NOT id = ANY (VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}) \ + ORDER BY ucid, published #{sort}", as: ChannelVideo) else videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} \ ORDER BY ucid, published #{sort}", as: ChannelVideo) @@ -1836,15 +1830,9 @@ get "/feed/subscriptions" do |env| videos.sort_by! { |video| video.published }.reverse! else if preferences.unseen_only - if user.watched.empty? - watched = "'{}'" - else - watched = arg_array(user.watched, 3) - end - videos = PG_DB.query_all("SELECT * FROM #{view_name} WHERE \ - id NOT IN (#{watched}) ORDER BY published #{sort} LIMIT $1 OFFSET $2", - [limit, offset] + user.watched, as: ChannelVideo) + NOT id = ANY (VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}) \ + ORDER BY published #{sort} LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo) else videos = PG_DB.query_all("SELECT * FROM #{view_name} \ ORDER BY published #{sort} LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)