From 6c8f7986f985be010607dbcaf51dcf362ce69082 Mon Sep 17 00:00:00 2001 From: Noah Saso Date: Thu, 6 Jun 2024 12:20:28 -0400 Subject: [PATCH] sped up and cache home page static props queries --- apps/dapp/pages/[[...tab]].tsx | 59 ++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/apps/dapp/pages/[[...tab]].tsx b/apps/dapp/pages/[[...tab]].tsx index cd64729d3..e31d5cc93 100644 --- a/apps/dapp/pages/[[...tab]].tsx +++ b/apps/dapp/pages/[[...tab]].tsx @@ -7,8 +7,8 @@ import { serverSideTranslations } from '@dao-dao/i18n/serverSideTranslations' import { daoQueries, dehydrateSerializable, + indexerQueries, makeReactQueryClient, - querySnapper, } from '@dao-dao/state' import { Home, @@ -25,6 +25,9 @@ import { export default Home +// Share query client across static props generators since the data is the same. +const queryClient = makeReactQueryClient() + export const getStaticProps: GetStaticProps = async ({ locale, params, @@ -63,35 +66,41 @@ export const getStaticProps: GetStaticProps = async ({ : []), ].map((chainId) => getDaoInfoForChainId(chainId, [])) - const queryClient = makeReactQueryClient() - const [i18nProps, tvl, allStats, monthStats, weekStats] = await Promise.all([ // Get i18n translations props. serverSideTranslations(locale, ['translation']), // Get all or chain-specific stats and TVL. - querySnapper({ - query: chainId ? 'daodao-chain-tvl' : 'daodao-all-tvl', - parameters: chainId ? { chainId } : undefined, - }), - querySnapper({ - query: chainId ? 'daodao-chain-stats' : 'daodao-all-stats', - parameters: chainId ? { chainId } : undefined, - }), - querySnapper({ - query: chainId ? 'daodao-chain-stats' : 'daodao-all-stats', - parameters: { - ...(chainId ? { chainId } : undefined), - daysAgo: 30, - }, - }), - querySnapper({ - query: chainId ? 'daodao-chain-stats' : 'daodao-all-stats', - parameters: { - ...(chainId ? { chainId } : undefined), - daysAgo: 7, - }, - }), + queryClient.fetchQuery( + indexerQueries.snapper({ + query: chainId ? 'daodao-chain-tvl' : 'daodao-all-tvl', + parameters: chainId ? { chainId } : undefined, + }) + ), + queryClient.fetchQuery( + indexerQueries.snapper({ + query: chainId ? 'daodao-chain-stats' : 'daodao-all-stats', + parameters: chainId ? { chainId } : undefined, + }) + ), + queryClient.fetchQuery( + indexerQueries.snapper({ + query: chainId ? 'daodao-chain-stats' : 'daodao-all-stats', + parameters: { + ...(chainId ? { chainId } : undefined), + daysAgo: 30, + }, + }) + ), + queryClient.fetchQuery( + indexerQueries.snapper({ + query: chainId ? 'daodao-chain-stats' : 'daodao-all-stats', + parameters: { + ...(chainId ? { chainId } : undefined), + daysAgo: 7, + }, + }) + ), // Pre-fetch featured DAOs. queryClient