mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Fix batch importing of channels
This commit is contained in:
parent
305d636217
commit
c728214af7
1 changed files with 26 additions and 15 deletions
|
@ -23,26 +23,37 @@ struct ChannelVideo
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_batch_channels(channels, db, refresh = false, pull_all_videos = true, max_threads = 10)
|
def get_batch_channels(channels, db, refresh = false, pull_all_videos = true, max_threads = 10)
|
||||||
active_threads = 0
|
finished_channel = Channel(String | Nil).new
|
||||||
active_channel = Channel(String | Nil).new
|
|
||||||
|
|
||||||
final = [] of String
|
spawn do
|
||||||
channels.map do |ucid|
|
active_threads = 0
|
||||||
if active_threads >= max_threads
|
active_channel = Channel(Nil).new
|
||||||
if response = active_channel.receive
|
|
||||||
|
channels.each do |ucid|
|
||||||
|
if active_threads >= max_threads
|
||||||
|
active_channel.receive
|
||||||
active_threads -= 1
|
active_threads -= 1
|
||||||
final << response
|
end
|
||||||
|
|
||||||
|
active_threads += 1
|
||||||
|
spawn do
|
||||||
|
begin
|
||||||
|
get_channel(ucid, db, refresh, pull_all_videos)
|
||||||
|
finished_channel.send(ucid)
|
||||||
|
rescue ex
|
||||||
|
finished_channel.send(nil)
|
||||||
|
ensure
|
||||||
|
active_channel.send(nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
active_threads += 1
|
final = [] of String
|
||||||
spawn do
|
channels.size.times do
|
||||||
begin
|
ucid = finished_channel.receive
|
||||||
get_channel(ucid, db, refresh, pull_all_videos)
|
if ucid
|
||||||
active_channel.send(ucid)
|
final << ucid
|
||||||
rescue ex
|
|
||||||
active_channel.send(nil)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue