mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-08 13:42:27 +05:30
Merge 389e6a7659
into d8b893e9ad
This commit is contained in:
commit
0570d2ee8c
@ -85,6 +85,25 @@ module Invidious::Database::Channels
|
||||
|
||||
return PG_DB.query_all(request, ids, as: InvidiousChannel)
|
||||
end
|
||||
|
||||
# Select channels sorted by last published video
|
||||
def select_sorted(ids : Array(String)) : Array(InvidiousChannel)?
|
||||
return [] of InvidiousChannel if ids.empty?
|
||||
|
||||
request = <<-SQL
|
||||
WITH max_published AS (
|
||||
SELECT ucid, MAX(published) AS last_published
|
||||
FROM channel_videos
|
||||
GROUP BY ucid
|
||||
)
|
||||
SELECT channels.id, channels.author, channels.subscribed, channels.updated, channels.deleted FROM channels
|
||||
LEFT JOIN max_published ON channels.id = max_published.ucid
|
||||
WHERE channels.id = ANY($1)
|
||||
ORDER BY max_published.last_published DESC NULLS LAST;
|
||||
SQL
|
||||
|
||||
return PG_DB.query_all(request, ids, as: InvidiousChannel)
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -153,7 +153,12 @@ module Invidious::Routes::API::V1::Authenticated
|
||||
env.response.content_type = "application/json"
|
||||
user = env.get("user").as(User)
|
||||
|
||||
subscriptions = Invidious::Database::Channels.select(user.subscriptions)
|
||||
sort = env.params.query["sort"]?.try &.== "last"
|
||||
if sort
|
||||
subscriptions = Invidious::Database::Channels.select_sorted(user.subscriptions)
|
||||
else
|
||||
subscriptions = Invidious::Database::Channels.select(user.subscriptions)
|
||||
end
|
||||
|
||||
JSON.build do |json|
|
||||
json.array do
|
||||
|
Loading…
Reference in New Issue
Block a user