diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-02-08 20:19:44 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-02-08 20:19:44 -0600 |
| commit | ecb1999795a24012c3556186a3f4f18abc6c3a95 (patch) | |
| tree | 966bab0bc48f847b276393b3732737b813213bda /src | |
| parent | a27c556904556bcd7407a485541dd54cedd5dca0 (diff) | |
| download | invidious-ecb1999795a24012c3556186a3f4f18abc6c3a95.tar.gz invidious-ecb1999795a24012c3556186a3f4f18abc6c3a95.tar.bz2 invidious-ecb1999795a24012c3556186a3f4f18abc6c3a95.zip | |
Ensure clients are recycled properly
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 5497ad3a..5373a84d 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -63,7 +63,11 @@ threads.times do ids << id end + pool << client + loop do + client = get_client(pool) + if ids.empty? search(random.base64(3), client) do |id| ids << id @@ -72,10 +76,9 @@ threads.times do if rand(300) < 1 pool << make_client(URL, CONTEXT) + client = get_client(pool) end - time = Time.now - begin id = ids[0] video = get_video(id, client, PG_DB) @@ -104,7 +107,7 @@ threads.times do end end - # io << Time.now << " 200 GET www.youtube.com/watch?v=" << video.id << " " << elapsed_text(Time.now - time) << "\n" + pool << client end end end @@ -113,7 +116,7 @@ top_videos = [] of Video spawn do loop do - top = rank_videos(PG_DB, 120) + top = rank_videos(PG_DB, 40) client = get_client(pool) args = [] of String @@ -121,16 +124,18 @@ spawn do args << "($#{top.size}) " args = args.join("") + videos = [] of Video + PG_DB.query("SELECT * FROM videos d INNER JOIN (VALUES #{args}) v(id) USING (id)", top) do |rs| rs.each do video = rs.read(Video) - top_videos << video + videos << video end end - pool << client + top_videos = videos - sleep 5.minutes + pool << client end end |
