From 728817fba2de1ed2f43802ed0efe02a3b7c00c6e Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 5 Feb 2017 03:19:04 +0100 Subject: [PATCH] Add tracking of delay to streaming API --- .../features/ui/containers/modal_container.jsx | 2 +- app/lib/feed_manager.rb | 1 + streaming/index.js | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/components/features/ui/containers/modal_container.jsx b/app/assets/javascripts/components/features/ui/containers/modal_container.jsx index 1e69fc59c8..334e5c1991 100644 --- a/app/assets/javascripts/components/features/ui/containers/modal_container.jsx +++ b/app/assets/javascripts/components/features/ui/containers/modal_container.jsx @@ -123,7 +123,7 @@ const Modal = React.createClass({ window.addEventListener('keyup', this._listener); }, - componentDidUnmount () { + componentWillUnmount () { window.removeEventListener('keyup', this._listener); }, diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 028fc5218b..7069026e36 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -30,6 +30,7 @@ class FeedManager end def broadcast(timeline_id, options = {}) + options[:queued_at] = (Time.now.to_f * 1000.0).to_i ActionCable.server.broadcast("timeline:#{timeline_id}", options) end diff --git a/streaming/index.js b/streaming/index.js index 16dda5c1e7..4f0df1ea56 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -101,7 +101,15 @@ const streamFrom = (redisClient, id, req, output, needsFiltering = false) => { log.verbose(`Starting stream from ${id} for ${req.accountId}`) redisClient.on('message', (channel, message) => { - const { event, payload } = JSON.parse(message) + const { event, payload, queued_at } = JSON.parse(message) + + const transmit = () => { + const now = new Date().getTime() + const delta = now - queued_at; + + log.silly(`Transmitting for ${req.accountId}: ${event} ${payload} Delay: ${delta}ms`) + output(event, payload) + } // Only messages that may require filtering are statuses, since notifications // are already personalized and deletes do not matter @@ -127,13 +135,11 @@ const streamFrom = (redisClient, id, req, output, needsFiltering = false) => { return } - log.silly(`Transmitting for ${req.accountId}: ${event} ${payload}`) - output(event, payload) + transmit() }) }) } else { - log.silly(`Transmitting for ${req.accountId}: ${event} ${payload}`) - output(event, payload) + transmit() } })