Prioritize videos that haven't been downloaded yet
This commit is contained in:
parent
fc9d25ba0d
commit
f8e2945266
9
main.rb
9
main.rb
@ -54,7 +54,14 @@ get '/videos.json' do
|
|||||||
if amount > 100_000
|
if amount > 100_000
|
||||||
{ error: "greedy" }.to_json
|
{ error: "greedy" }.to_json
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user