diff options
| author | Omar Roth <omarroth@protonmail.com> | 2019-06-03 13:36:49 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@protonmail.com> | 2019-06-03 13:36:49 -0500 |
| commit | d6ec441c8ef418ebb8be625e4ee7738cdda62597 (patch) | |
| tree | 10c0809d8e3818f4deff4ed35a8d81feb14c174c /src | |
| parent | d19749734985c1cc057a27494bbaf64a54bcf348 (diff) | |
| download | invidious-d6ec441c8ef418ebb8be625e4ee7738cdda62597.tar.gz invidious-d6ec441c8ef418ebb8be625e4ee7738cdda62597.tar.bz2 invidious-d6ec441c8ef418ebb8be625e4ee7738cdda62597.zip | |
Add buffer for notification channels
Diffstat (limited to 'src')
| -rw-r--r-- | src/invidious.cr | 2 | ||||
| -rw-r--r-- | src/invidious/helpers/helpers.cr | 18 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index e1e9af2a..24dcaf7e 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -186,7 +186,7 @@ spawn do end end -connection_channel = Channel({Bool, Channel(PQ::Notification)}).new +connection_channel = Channel({Bool, Channel(PQ::Notification)}).new(32) spawn do connections = [] of Channel(PQ::Notification) diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 699fc374..2dd50d42 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -662,7 +662,7 @@ def copy_in_chunks(input, output, chunk_size = 4096) end def create_notification_stream(env, proxies, config, kemal_config, decrypt_function, topics, connection_channel) - connection = Channel(PQ::Notification).new + connection = Channel(PQ::Notification).new(8) connection_channel.send({true, connection}) locale = LOCALES[env.get("preferences").as(Preferences).locale]? @@ -750,6 +750,10 @@ def create_notification_stream(env, proxies, config, kemal_config, decrypt_funct video_id = notification["videoId"].as_s published = notification["published"].as_i64 + if !topics.try &.includes? topic + next + end + video = get_video(video_id, PG_DB, proxies) video.published = Time.unix(published) response = JSON.parse(video.to_json(locale, config, Kemal.config, decrypt_function)) @@ -763,14 +767,12 @@ def create_notification_stream(env, proxies, config, kemal_config, decrypt_funct end end - if topics.try &.includes? topic - env.response.puts "id: #{id}" - env.response.puts "data: #{response.to_json}" - env.response.puts - env.response.flush + env.response.puts "id: #{id}" + env.response.puts "data: #{response.to_json}" + env.response.puts + env.response.flush - id += 1 - end + id += 1 end rescue ex ensure |
