# Show latest video from a channel that a user hasn't watched
# 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"
# "unseen_only" isn't really correct here, more accurate would be "unwatched_only"
ifuser.watched.empty?
# "SELECT cv.* FROM channel_videos cv JOIN users ON cv.ucid = any(users.subscriptions) WHERE users.email = $1 AND published > now() - interval '1 month' ORDER BY published DESC"
values="'{}'"
# "SELECT DISTINCT ON (cv.ucid) cv.* FROM channel_videos cv JOIN users ON cv.ucid = any(users.subscriptions) WHERE users.email = ? AND NOT cv.id = any(users.watched) AND published > now() - interval '1 month' ORDER BY ucid, published DESC"
else
videos=PG_DB.query_all("SELECT DISTINCT ON (cv.ucid) cv.* "\
"ORDER BY published DESC LIMIT $2 OFFSET $3",user.email,limit,offset,as:ChannelVideo)
end
videos=PG_DB.query_all("SELECT * FROM #{view_name} WHERE NOT id = ANY (#{values}) ORDER BY published DESC LIMIT $1 OFFSET $2",limit,offset,as:ChannelVideo)
else
else
# Sort subscriptions as normal
# Sort subscriptions as normal
videos=PG_DB.query_all("SELECT cv.* "\
videos=PG_DB.query_all("SELECT * FROM #{view_name} ORDER BY published DESC LIMIT $1 OFFSET $2",limit,offset,as:ChannelVideo)
"FROM channel_videos cv "\
"JOIN users ON cv.ucid = any(users.subscriptions) "\
"WHERE users.email = $1 AND published > now() - interval '1 month' "\
"ORDER BY published DESC LIMIT $2 OFFSET $3",user.email,limit,offset,as:ChannelVideo)