videos=PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE NOT id = ANY (#{values}) ORDER BY ucid, published DESC",as:ChannelVideo)
# "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"
# "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"
videos=PG_DB.query_all("SELECT DISTINCT ON (cv.ucid) cv.* "\
"FROM channel_videos cv "\
"JOIN users ON cv.ucid = any(users.subscriptions) "\
"WHERE users.email = $1 AND NOT cv.id = any(users.watched) AND published > now() - interval '1 month' "\
"ORDER BY ucid, published DESC",user.email,as:ChannelVideo)
else
# Show latest video from each channel
videos=PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} ORDER BY ucid, published DESC",as:ChannelVideo)
videos=PG_DB.query_all("SELECT DISTINCT ON (cv.ucid) 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 ucid, published DESC",user.email,as:ChannelVideo)
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)
videos=PG_DB.query_all("SELECT cv.* "\
"FROM channel_videos cv "\
"JOIN users ON cv.ucid = any(users.subscriptions) "\
"WHERE users.email = $1 AND NOT cv.id = any(users.watched) AND published > now() - interval '1 month' "\
"ORDER BY published DESC LIMIT $2 OFFSET $3",user.email,limit,offset,as:ChannelVideo)
else
# Sort subscriptions as normal
videos=PG_DB.query_all("SELECT * FROM #{view_name} ORDER BY published DESC LIMIT $1 OFFSET $2",limit,offset,as:ChannelVideo)
videos=PG_DB.query_all("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 LIMIT $2 OFFSET $3",user.email,limit,offset,as:ChannelVideo)