From 9a36a0b318fee5f6e6deb191612cc2a6ff449402 Mon Sep 17 00:00:00 2001 From: justinschuldt Date: Thu, 17 Mar 2022 14:58:42 -0500 Subject: [PATCH] explorer - increase poll interval --- .../ExplorerStats/ExplorerStats.tsx | 33 ++++++++++++++++--- explorer/src/pages/index.tsx | 6 ---- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/explorer/src/components/ExplorerStats/ExplorerStats.tsx b/explorer/src/components/ExplorerStats/ExplorerStats.tsx index c34caed77..7dd297fc7 100644 --- a/explorer/src/components/ExplorerStats/ExplorerStats.tsx +++ b/explorer/src/components/ExplorerStats/ExplorerStats.tsx @@ -335,7 +335,12 @@ const ExplorerStats: React.FC = ({ ); }; - const getData = (props: StatsProps, baseUrl: string, signal: AbortSignal) => { + const getData = (props: StatsProps, baseUrl: string, signal: AbortSignal, func: (baseUrl: string, + recentGroupBy: GroupBy, + totalsGroupBy: GroupBy, + forChain: ForChain, + forAddress: string | undefined, + signal: AbortSignal) => Promise) => { let forChain: ForChain = undefined; let forAddress: ForAddress = undefined; let recentGroupBy: GroupBy = undefined; @@ -348,6 +353,15 @@ const ExplorerStats: React.FC = ({ if (props.emitterChain && props.emitterAddress) { forAddress = props.emitterAddress; } + return func(baseUrl, recentGroupBy, totalsGroupBy, forChain, forAddress, signal) + }; + const getAllEndpoints = ( + baseUrl: string, + recentGroupBy: GroupBy, + totalsGroupBy: GroupBy, + forChain: ForChain, + forAddress: string | undefined, + signal: AbortSignal) => { return Promise.all([ fetchTotals(baseUrl, totalsGroupBy, forChain, forAddress, signal), fetchRecent(baseUrl, recentGroupBy, forChain, forAddress, signal), @@ -362,11 +376,19 @@ const ExplorerStats: React.FC = ({ ), ]); }; + const getRecents = ( + baseUrl: string, + recentGroupBy: GroupBy, + totalsGroupBy: GroupBy, + forChain: ForChain, + forAddress: string | undefined, + signal: AbortSignal) => fetchRecent(baseUrl, recentGroupBy, forChain, forAddress, signal) + const pollingController = ( emitterChain: StatsProps["emitterChain"], emitterAddress: StatsProps["emitterAddress"], - baseUrl: string + baseUrl: string, ) => { // clear any ongoing intervals if (pollInterval) { @@ -382,8 +404,8 @@ const ExplorerStats: React.FC = ({ const { signal } = newController; // start polling let interval = setInterval(() => { - getData({ emitterChain, emitterAddress }, baseUrl, signal); - }, 12000); + getData({ emitterChain, emitterAddress }, baseUrl, signal, getRecents); + }, 30000); setPollInterval(interval); }; @@ -397,7 +419,8 @@ const ExplorerStats: React.FC = ({ getData( { emitterChain, emitterAddress }, activeNetwork.endpoints.bigtableFunctionsBase, - new AbortController().signal + new AbortController().signal, + getAllEndpoints ); } controller.abort(); diff --git a/explorer/src/pages/index.tsx b/explorer/src/pages/index.tsx index 11f062277..c3d36ab9b 100644 --- a/explorer/src/pages/index.tsx +++ b/explorer/src/pages/index.tsx @@ -37,7 +37,6 @@ const IndexPage = ({ location }: PageProps) => { const [tvl, setTvl] = useState(undefined) const [messageTotal, setMessageTotal] = useState(undefined) - let statsInterval: NodeJS.Timer | undefined = undefined const controller = new AbortController() const { signal } = controller @@ -122,7 +121,6 @@ const IndexPage = ({ location }: PageProps) => { useEffect(() => { fetchStats() // fetchStats on first load - statsInterval = setInterval(fetchStats, 30000) // fetch every 30 seconds gsap.registerPlugin(ScrollTrigger); @@ -184,10 +182,6 @@ const IndexPage = ({ location }: PageProps) => { return function cleanup() { - // clear any ongoing intervals - if (statsInterval) { - clearInterval(statsInterval); - } // abort any in-flight requests controller.abort(); }