From 94973cc980addf2d25969177645b5ce72630ec2c Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 9 Sep 2015 15:03:40 -0700 Subject: [PATCH] perf(delta-sync): Don't update work UI when window is hidden, don't save config as often (synchronous IPC) --- .../worker-sync/lib/nylas-long-connection.coffee | 13 +++++++------ .../worker-ui/lib/developer-bar-store.coffee | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal_packages/worker-sync/lib/nylas-long-connection.coffee b/internal_packages/worker-sync/lib/nylas-long-connection.coffee index 57064799c..b94f746b9 100644 --- a/internal_packages/worker-sync/lib/nylas-long-connection.coffee +++ b/internal_packages/worker-sync/lib/nylas-long-connection.coffee @@ -23,8 +23,15 @@ class NylasLongConnection @_deltas = [] @_flushDeltasDebounced = _.debounce => + + return if @_deltas.length is 0 + last = @_deltas[@_deltas.length - 1] + @_emitter.emit('deltas-stopped-arriving', @_deltas) @_deltas = [] + + # Note: setCursor is slow and saves to disk, so we do it once at the end + @setCursor(last.cursor) , 1000 @ @@ -69,7 +76,6 @@ class NylasLongConnection onProcessBuffer: => bufferJSONs = @_buffer.split('\n') - bufferCursor = null # We can't parse the last block - we don't know whether we've # received the entire delta or only part of it. Wait @@ -87,11 +93,6 @@ class NylasLongConnection throw (new Error 'Received delta with no cursor!') unless delta.cursor @_deltas.push(delta) @_flushDeltasDebounced() - bufferCursor = delta.cursor - - # Note: setCursor is slow and saves to disk, so we do it once at the end - if bufferCursor - @setCursor(bufferCursor) start: -> token = @_api.accessTokenForAccountId(@_accountId) diff --git a/internal_packages/worker-ui/lib/developer-bar-store.coffee b/internal_packages/worker-ui/lib/developer-bar-store.coffee index 0c71113a8..a59a093aa 100644 --- a/internal_packages/worker-ui/lib/developer-bar-store.coffee +++ b/internal_packages/worker-ui/lib/developer-bar-store.coffee @@ -27,7 +27,8 @@ class DeveloperBarStore extends NylasStore triggerThrottled: -> @_triggerThrottled ?= _.throttle(@trigger, 100) - @_triggerThrottled() + if atom.getCurrentWindow().isVisible() + @_triggerThrottled() _setStoreDefaults: -> @_curlHistory = {}