From 06f6aa7a00f57004746d1e21759ac56396d9b855 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 15 Jun 2017 18:00:24 -0700 Subject: [PATCH] Debounce background updates Our background sometimes emits absurd quantities of updates very quickly. This PR reduces the amount of inter-process traffic by ensuring the `sendUpdate` method does not fire more than every 200 ms. Fixes #1621 --- app/scripts/metamask-controller.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a7eb3d056..d745d29dc 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -23,6 +23,7 @@ const autoFaucet = require('./lib/auto-faucet') const nodeify = require('./lib/nodeify') const accountImporter = require('./account-import-strategies') const getBuyEthUrl = require('./lib/buy-eth-url') +const debounce = require('debounce') const version = require('../manifest.json').version @@ -30,6 +31,9 @@ module.exports = class MetamaskController extends EventEmitter { constructor (opts) { super() + + this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200) + this.opts = opts const initState = opts.initState || {} @@ -354,7 +358,7 @@ module.exports = class MetamaskController extends EventEmitter { ) } - sendUpdate () { + privateSendUpdate () { this.emit('update', this.getState()) }