Compare commits

...

7 Commits

Author SHA1 Message Date
Brahim Hadriche 126be83e68
Merge 389e6a7659 into b673695aa2 2024-04-17 05:30:43 -04:00
Émilien (perso) b673695aa2
Merge pull request #4561 from ChunkyProgrammer/use-trending-api-for-health-checks
Use Trending API for health checks
2024-04-10 20:21:17 +07:00
ChunkyProgrammer 170eef58fd Use trending api for health checks 2024-04-04 19:10:27 -04:00
Brahim Hadriche 389e6a7659 Merge branch 'master' into feature/sorted-channels 2024-03-27 00:12:32 -04:00
Brahim Hadriche 3a84359e7d Rename param 2023-12-08 07:38:32 -05:00
Brahim Hadriche 58f66761fb Format 2023-10-29 16:03:42 -04:00
Brahim Hadriche 7ca72c5b6f channels sorted by last published video 2023-10-29 15:54:53 -04:00
3 changed files with 26 additions and 2 deletions

View File

@ -32,7 +32,7 @@ services:
# statistics_enabled: false
hmac_key: "CHANGE_ME!!"
healthcheck:
test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/comments/jNQXAC9IVRw || exit 1
test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/trending || exit 1
interval: 30s
timeout: 5s
retries: 2

View File

@ -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
#

View File

@ -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