Delay prefetch by 1000ms. Don't prefetch portfolio history.

This commit is contained in:
James Grugett 2022-09-23 16:30:44 -04:00
parent 0ab82a7bd4
commit 1a5dcdedcc
5 changed files with 9 additions and 8 deletions

View File

@ -1,3 +1,6 @@
export const MINUTE_MS = 60 * 1000 export const MINUTE_MS = 60 * 1000
export const HOUR_MS = 60 * MINUTE_MS export const HOUR_MS = 60 * MINUTE_MS
export const DAY_MS = 24 * HOUR_MS export const DAY_MS = 24 * HOUR_MS
export const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms))

View File

@ -11,7 +11,7 @@ import {
trendingContractsQuery, trendingContractsQuery,
} from 'web/lib/firebase/contracts' } from 'web/lib/firebase/contracts'
import { QueryClient, useQuery, useQueryClient } from 'react-query' import { QueryClient, useQuery, useQueryClient } from 'react-query'
import { MINUTE_MS } from 'common/util/time' import { MINUTE_MS, sleep } from 'common/util/time'
import { query, limit } from 'firebase/firestore' import { query, limit } from 'firebase/firestore'
import { dailyScoreIndex } from 'web/lib/service/algolia' import { dailyScoreIndex } from 'web/lib/service/algolia'
import { CPMMBinaryContract } from 'common/contract' import { CPMMBinaryContract } from 'common/contract'
@ -86,7 +86,7 @@ export const usePrefetchUserBetContracts = (userId: string) => {
const queryClient = useQueryClient() const queryClient = useQueryClient()
return queryClient.prefetchQuery( return queryClient.prefetchQuery(
['contracts', 'bets', userId], ['contracts', 'bets', userId],
() => getUserBetContracts(userId), () => sleep(1000).then(() => getUserBetContracts(userId)),
{ staleTime: 5 * MINUTE_MS } { staleTime: 5 * MINUTE_MS }
) )
} }

View File

@ -1,6 +1,6 @@
import { useQueryClient } from 'react-query' import { useQueryClient } from 'react-query'
import { useFirestoreQueryData } from '@react-query-firebase/firestore' import { useFirestoreQueryData } from '@react-query-firebase/firestore'
import { DAY_MS, HOUR_MS, MINUTE_MS } from 'common/util/time' import { DAY_MS, HOUR_MS, MINUTE_MS, sleep } from 'common/util/time'
import { import {
getPortfolioHistory, getPortfolioHistory,
getPortfolioHistoryQuery, getPortfolioHistoryQuery,
@ -17,7 +17,7 @@ export const usePrefetchPortfolioHistory = (userId: string, period: Period) => {
const cutoff = getCutoff(period) const cutoff = getCutoff(period)
return queryClient.prefetchQuery( return queryClient.prefetchQuery(
['portfolio-history', userId, cutoff], ['portfolio-history', userId, cutoff],
() => getPortfolioHistory(userId, cutoff), () => sleep(1000).then(() => getPortfolioHistory(userId, cutoff)),
{ staleTime: 15 * MINUTE_MS } { staleTime: 15 * MINUTE_MS }
) )
} }

View File

@ -1,5 +1,4 @@
import { usePrefetchUserBetContracts } from './use-contracts' import { usePrefetchUserBetContracts } from './use-contracts'
import { usePrefetchPortfolioHistory } from './use-portfolio-history'
import { usePrefetchUserBets } from './use-user-bets' import { usePrefetchUserBets } from './use-user-bets'
export function usePrefetch(userId: string | undefined) { export function usePrefetch(userId: string | undefined) {
@ -7,6 +6,5 @@ export function usePrefetch(userId: string | undefined) {
return Promise.all([ return Promise.all([
usePrefetchUserBets(maybeUserId), usePrefetchUserBets(maybeUserId),
usePrefetchUserBetContracts(maybeUserId), usePrefetchUserBetContracts(maybeUserId),
usePrefetchPortfolioHistory(maybeUserId, 'weekly'),
]) ])
} }

View File

@ -7,13 +7,13 @@ import {
getUserBetsQuery, getUserBetsQuery,
listenForUserContractBets, listenForUserContractBets,
} from 'web/lib/firebase/bets' } from 'web/lib/firebase/bets'
import { MINUTE_MS } from 'common/util/time' import { MINUTE_MS, sleep } from 'common/util/time'
export const usePrefetchUserBets = (userId: string) => { export const usePrefetchUserBets = (userId: string) => {
const queryClient = useQueryClient() const queryClient = useQueryClient()
return queryClient.prefetchQuery( return queryClient.prefetchQuery(
['bets', userId], ['bets', userId],
() => getUserBets(userId), () => sleep(1000).then(() => getUserBets(userId)),
{ staleTime: MINUTE_MS } { staleTime: MINUTE_MS }
) )
} }