mirror of
https://github.com/iv-org/invidious.git
synced 2026-01-27 23:38:28 -06:00
Filter shorts/livestreams in SQL
[src/invidious/users.cr] - Filter out shorts and livestreams in SQL rather than via an array selector. This way, in the relevant cases, we will query and return "limit" amount of videos, rather than a possible lower amount
This commit is contained in:
parent
0bce7311c2
commit
b8e7202cbf
@ -58,11 +58,18 @@ def get_subscription_feed(user, max_results = 40, page = 1)
|
|||||||
else
|
else
|
||||||
values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}"
|
values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}"
|
||||||
end
|
end
|
||||||
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE NOT id = ANY (#{values}) ORDER BY ucid, published DESC", as: ChannelVideo)
|
if user.preferences.hide_shorts_and_live
|
||||||
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE NOT id = ANY (#{values}) AND length_seconds > 0 ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||||
|
else
|
||||||
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} WHERE NOT id = ANY (#{values}) ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# Show latest video from each channel
|
# Show latest video from each channel
|
||||||
|
if user.preferences.hide_shorts_and_live
|
||||||
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 (ucid) * FROM #{view_name} WHERE length_seconds > 0 ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||||
|
else
|
||||||
|
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} ORDER BY ucid, published DESC", as: ChannelVideo)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
videos.sort_by!(&.published).reverse!
|
videos.sort_by!(&.published).reverse!
|
||||||
@ -75,18 +82,21 @@ def get_subscription_feed(user, max_results = 40, page = 1)
|
|||||||
else
|
else
|
||||||
values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}"
|
values = "VALUES #{user.watched.map { |id| %(('#{id}')) }.join(",")}"
|
||||||
end
|
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)
|
if user.preferences.hide_shorts_and_live
|
||||||
|
videos = PG_DB.query_all("SELECT * FROM #{view_name} WHERE NOT id = ANY (#{values}) AND length_seconds > 0 ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||||
|
else
|
||||||
|
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)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# Sort subscriptions as normal
|
# Sort subscriptions as normal
|
||||||
|
if user.preferences.hide_shorts_and_live
|
||||||
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 * FROM #{view_name} WHERE length_seconds > 0 ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||||
|
else
|
||||||
|
videos = PG_DB.query_all("SELECT * FROM #{view_name} ORDER BY published DESC LIMIT $1 OFFSET $2", limit, offset, as: ChannelVideo)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if user.preferences.hide_shorts_and_live
|
|
||||||
videos = videos.select { |v| v.length_seconds > 0 }
|
|
||||||
end
|
|
||||||
|
|
||||||
case user.preferences.sort
|
case user.preferences.sort
|
||||||
when "published - reverse"
|
when "published - reverse"
|
||||||
videos.sort_by!(&.published)
|
videos.sort_by!(&.published)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user