kopia lustrzana https://github.com/iv-org/invidious
Fix batch importing of channels
rodzic
305d636217
commit
c728214af7
|
@ -23,28 +23,39 @@ struct ChannelVideo
|
|||
end
|
||||
|
||||
def get_batch_channels(channels, db, refresh = false, pull_all_videos = true, max_threads = 10)
|
||||
active_threads = 0
|
||||
active_channel = Channel(String | Nil).new
|
||||
finished_channel = Channel(String | Nil).new
|
||||
|
||||
final = [] of String
|
||||
channels.map do |ucid|
|
||||
spawn do
|
||||
active_threads = 0
|
||||
active_channel = Channel(Nil).new
|
||||
|
||||
channels.each do |ucid|
|
||||
if active_threads >= max_threads
|
||||
if response = active_channel.receive
|
||||
active_channel.receive
|
||||
active_threads -= 1
|
||||
final << response
|
||||
end
|
||||
end
|
||||
|
||||
active_threads += 1
|
||||
spawn do
|
||||
begin
|
||||
get_channel(ucid, db, refresh, pull_all_videos)
|
||||
active_channel.send(ucid)
|
||||
finished_channel.send(ucid)
|
||||
rescue ex
|
||||
finished_channel.send(nil)
|
||||
ensure
|
||||
active_channel.send(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
final = [] of String
|
||||
channels.size.times do
|
||||
ucid = finished_channel.receive
|
||||
if ucid
|
||||
final << ucid
|
||||
end
|
||||
end
|
||||
|
||||
return final
|
||||
end
|
||||
|
|
Ładowanie…
Reference in New Issue