From 03f94db5e2541cb9474d90737d9c0ae95609835a Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 2 Mar 2019 20:13:41 -0600 Subject: [PATCH] Fix watch filtering from subscription feed when watch history is empty --- src/invidious.cr | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 20bb703b..cbcba12e 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1948,8 +1948,13 @@ get "/feed/subscriptions" do |env| # Show latest video from a channel that a user hasn't watched # "unseen_only" isn't really correct here, more accurate would be "unwatched_only" + if user.watched.empty? + values = "'{}'" + else + values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}" + end videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE \ - NOT id = ANY (VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}) \ + NOT id = ANY (#{values}) \ ORDER BY ucid, published #{sort}", as: ChannelVideo) else # Show latest video from each channel @@ -1963,8 +1968,13 @@ get "/feed/subscriptions" do |env| if preferences.unseen_only # Only show unwatched + if user.watched.empty? + values = "'{}'" + else + values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}" + end videos = PG_DB.query_all("SELECT * FROM #{view_name} WHERE \ - NOT id = ANY (VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}) \ + NOT id = ANY (#{values}) \ ORDER BY published #{sort} LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo) else # Sort subscriptions as normal