explorer - increase poll interval

This commit is contained in:
justinschuldt 2022-03-17 14:58:42 -05:00 committed by Justin Schuldt
parent 32634f87e6
commit 9a36a0b318
2 changed files with 28 additions and 11 deletions

View File

@ -335,7 +335,12 @@ const ExplorerStats: React.FC<StatsProps> = ({
); );
}; };
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<any>) => {
let forChain: ForChain = undefined; let forChain: ForChain = undefined;
let forAddress: ForAddress = undefined; let forAddress: ForAddress = undefined;
let recentGroupBy: GroupBy = undefined; let recentGroupBy: GroupBy = undefined;
@ -348,6 +353,15 @@ const ExplorerStats: React.FC<StatsProps> = ({
if (props.emitterChain && props.emitterAddress) { if (props.emitterChain && props.emitterAddress) {
forAddress = 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([ return Promise.all([
fetchTotals(baseUrl, totalsGroupBy, forChain, forAddress, signal), fetchTotals(baseUrl, totalsGroupBy, forChain, forAddress, signal),
fetchRecent(baseUrl, recentGroupBy, forChain, forAddress, signal), fetchRecent(baseUrl, recentGroupBy, forChain, forAddress, signal),
@ -362,11 +376,19 @@ const ExplorerStats: React.FC<StatsProps> = ({
), ),
]); ]);
}; };
const getRecents = (
baseUrl: string,
recentGroupBy: GroupBy,
totalsGroupBy: GroupBy,
forChain: ForChain,
forAddress: string | undefined,
signal: AbortSignal) => fetchRecent(baseUrl, recentGroupBy, forChain, forAddress, signal)
const pollingController = ( const pollingController = (
emitterChain: StatsProps["emitterChain"], emitterChain: StatsProps["emitterChain"],
emitterAddress: StatsProps["emitterAddress"], emitterAddress: StatsProps["emitterAddress"],
baseUrl: string baseUrl: string,
) => { ) => {
// clear any ongoing intervals // clear any ongoing intervals
if (pollInterval) { if (pollInterval) {
@ -382,8 +404,8 @@ const ExplorerStats: React.FC<StatsProps> = ({
const { signal } = newController; const { signal } = newController;
// start polling // start polling
let interval = setInterval(() => { let interval = setInterval(() => {
getData({ emitterChain, emitterAddress }, baseUrl, signal); getData({ emitterChain, emitterAddress }, baseUrl, signal, getRecents);
}, 12000); }, 30000);
setPollInterval(interval); setPollInterval(interval);
}; };
@ -397,7 +419,8 @@ const ExplorerStats: React.FC<StatsProps> = ({
getData( getData(
{ emitterChain, emitterAddress }, { emitterChain, emitterAddress },
activeNetwork.endpoints.bigtableFunctionsBase, activeNetwork.endpoints.bigtableFunctionsBase,
new AbortController().signal new AbortController().signal,
getAllEndpoints
); );
} }
controller.abort(); controller.abort();

View File

@ -37,7 +37,6 @@ const IndexPage = ({ location }: PageProps) => {
const [tvl, setTvl] = useState<number | undefined>(undefined) const [tvl, setTvl] = useState<number | undefined>(undefined)
const [messageTotal, setMessageTotal] = useState<number | undefined>(undefined) const [messageTotal, setMessageTotal] = useState<number | undefined>(undefined)
let statsInterval: NodeJS.Timer | undefined = undefined
const controller = new AbortController() const controller = new AbortController()
const { signal } = controller const { signal } = controller
@ -122,7 +121,6 @@ const IndexPage = ({ location }: PageProps) => {
useEffect(() => { useEffect(() => {
fetchStats() // fetchStats on first load fetchStats() // fetchStats on first load
statsInterval = setInterval(fetchStats, 30000) // fetch every 30 seconds
gsap.registerPlugin(ScrollTrigger); gsap.registerPlugin(ScrollTrigger);
@ -184,10 +182,6 @@ const IndexPage = ({ location }: PageProps) => {
return function cleanup() { return function cleanup() {
// clear any ongoing intervals
if (statsInterval) {
clearInterval(statsInterval);
}
// abort any in-flight requests // abort any in-flight requests
controller.abort(); controller.abort();
} }