Prioritize videos that haven't been downloaded yet

This commit is contained in:
Hugo Peixoto 2023-07-30 01:13:02 +01:00
parent fc9d25ba0d
commit f8e2945266

View File

@ -54,7 +54,14 @@ get '/videos.json' do
if amount > 100_000
{ error: "greedy" }.to_json
else
{ videos: Video.order("RANDOM()").limit(amount).pluck(:randname) }.to_json
videos = Video
.left_outer_joins(:downloads)
.group("randname")
.order("COUNT(1) ASC, RANDOM()")
.limit(amount)
.pluck(:randname)
{ videos: videos }.to_json
end
end