From 71e80f10d88d8ea0d3bcc0c15c94bd9f321c2776 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 5 Jan 2017 17:20:10 +0100 Subject: [PATCH] reverse caching: optimize timing Users quickly want all reverses registered in the path, but don't care so much about live data. --- js/src/redux/providers/registry/middleware.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/js/src/redux/providers/registry/middleware.js b/js/src/redux/providers/registry/middleware.js index 2fda34a56..87d9fbf70 100644 --- a/js/src/redux/providers/registry/middleware.js +++ b/js/src/redux/providers/registry/middleware.js @@ -25,7 +25,7 @@ export default class RegistryMiddleware { toMiddleware () { return (store) => { const api = Contracts.get()._api; - let contract, confirmedEvents, removedEvents, interval; + let contract, confirmedEvents, removedEvents, timeout, interval; let addressesToCheck = {}; @@ -77,7 +77,8 @@ export default class RegistryMiddleware { removedEvents = subscribeToEvent(_contract, 'ReverseRemoved'); removedEvents.on('log', onLog); - interval = setInterval(checkReverses, 2000); + timeout = setTimeout(checkReverses, 5000); + interval = setInterval(checkReverses, 20000); }) .catch((err) => { console.error('Failed to start caching reverses:', err); @@ -95,6 +96,9 @@ export default class RegistryMiddleware { if (interval) { clearInterval(interval); } + if (timeout) { + clearTimeout(timeout); + } break; default: @@ -103,4 +107,4 @@ export default class RegistryMiddleware { }; }; } -}; +}