diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-21 06:07:16 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-21 06:07:16 +0800 |
commit | c858ff61f7ef8b1941f3f5832713b1d87d92a2af (patch) | |
tree | 51c4ba797ba39788e185229b221f639020e0ba0d /packages/0x.js | |
parent | 037f466e1f80f635b48f3235258402e2ce75fb7b (diff) | |
download | dexon-sol-tools-c858ff61f7ef8b1941f3f5832713b1d87d92a2af.tar dexon-sol-tools-c858ff61f7ef8b1941f3f5832713b1d87d92a2af.tar.gz dexon-sol-tools-c858ff61f7ef8b1941f3f5832713b1d87d92a2af.tar.bz2 dexon-sol-tools-c858ff61f7ef8b1941f3f5832713b1d87d92a2af.tar.lz dexon-sol-tools-c858ff61f7ef8b1941f3f5832713b1d87d92a2af.tar.xz dexon-sol-tools-c858ff61f7ef8b1941f3f5832713b1d87d92a2af.tar.zst dexon-sol-tools-c858ff61f7ef8b1941f3f5832713b1d87d92a2af.zip |
Add an order state cache to filter out duplicate events
Diffstat (limited to 'packages/0x.js')
-rw-r--r-- | packages/0x.js/src/order_watcher/order_state_watcher.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts index 33fa69b1c..648345c48 100644 --- a/packages/0x.js/src/order_watcher/order_state_watcher.ts +++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts @@ -43,6 +43,10 @@ interface OrderByOrderHash { [orderHash: string]: SignedOrder; } +interface OrderStateByOrderHash { + [orderHash: string]: OrderState; +} + /** * This class includes all the functionality related to watching a set of orders * for potential changes in order validity/fillability. The orderWatcher notifies @@ -50,6 +54,7 @@ interface OrderByOrderHash { * the order should be deemed invalid. */ export class OrderStateWatcher { + private _orderStateByOrderHashCache: OrderStateByOrderHash = {}; private _orderByOrderHash: OrderByOrderHash = {}; private _dependentOrderHashes: DependentOrderHashes = {}; private _callbackIfExists?: OnOrderStateChangeCallback; @@ -96,6 +101,7 @@ export class OrderStateWatcher { return; // noop } delete this._orderByOrderHash[orderHash]; + delete this._orderStateByOrderHashCache[orderHash]; const exchange = (this._orderFilledCancelledLazyStore as any).exchange as ExchangeWrapper; const zrxTokenAddress = await exchange.getZRXTokenAddressAsync(); this.removeFromDependentOrderHashes(signedOrder.maker, zrxTokenAddress, orderHash); @@ -210,6 +216,12 @@ export class OrderStateWatcher { if (_.isUndefined(this._callbackIfExists)) { break; // Unsubscribe was called } + if (_.isEqual(orderState, this._orderStateByOrderHashCache[orderHash])) { + // Actual order state didn't change + continue; + } else { + this._orderStateByOrderHashCache[orderHash] = orderState; + } this._callbackIfExists(orderState); } } |