Use algolia to fetch daily movers so it's faster.
This commit is contained in:
parent
a14e7d3947
commit
436646cc47
|
@ -1,6 +1,5 @@
|
||||||
import { usePrefetchUserBetContracts } from './use-contracts'
|
import { usePrefetchUserBetContracts } from './use-contracts'
|
||||||
import { usePrefetchPortfolioHistory } from './use-portfolio-history'
|
import { usePrefetchPortfolioHistory } from './use-portfolio-history'
|
||||||
import { usePrefetchProbChanges } from './use-prob-changes'
|
|
||||||
import { usePrefetchUserBets } from './use-user-bets'
|
import { usePrefetchUserBets } from './use-user-bets'
|
||||||
|
|
||||||
export function usePrefetch(userId: string | undefined) {
|
export function usePrefetch(userId: string | undefined) {
|
||||||
|
@ -9,6 +8,5 @@ export function usePrefetch(userId: string | undefined) {
|
||||||
usePrefetchUserBets(maybeUserId),
|
usePrefetchUserBets(maybeUserId),
|
||||||
usePrefetchUserBetContracts(maybeUserId),
|
usePrefetchUserBetContracts(maybeUserId),
|
||||||
usePrefetchPortfolioHistory(maybeUserId, 'weekly'),
|
usePrefetchPortfolioHistory(maybeUserId, 'weekly'),
|
||||||
usePrefetchProbChanges(userId),
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,39 @@
|
||||||
import { useFirestoreQueryData } from '@react-query-firebase/firestore'
|
import { useFirestoreQueryData } from '@react-query-firebase/firestore'
|
||||||
|
import { CPMMContract } from 'common/contract'
|
||||||
import { MINUTE_MS } from 'common/util/time'
|
import { MINUTE_MS } from 'common/util/time'
|
||||||
import { useQueryClient } from 'react-query'
|
import { useQuery, useQueryClient } from 'react-query'
|
||||||
import {
|
import {
|
||||||
getProbChangesNegative,
|
getProbChangesNegative,
|
||||||
getProbChangesPositive,
|
getProbChangesPositive,
|
||||||
} from 'web/lib/firebase/contracts'
|
} from 'web/lib/firebase/contracts'
|
||||||
import { getValues } from 'web/lib/firebase/utils'
|
import { getValues } from 'web/lib/firebase/utils'
|
||||||
|
import { getIndexName, searchClient } from 'web/lib/service/algolia'
|
||||||
|
|
||||||
|
export const useProbChangesAlgolia = (userId: string) => {
|
||||||
|
const { data: positiveData } = useQuery(['prob-change-day', userId], () =>
|
||||||
|
searchClient
|
||||||
|
.initIndex(getIndexName('prob-change-day'))
|
||||||
|
.search<CPMMContract>('', { facetFilters: ['uniqueBettorIds:' + userId] })
|
||||||
|
)
|
||||||
|
const { data: negativeData } = useQuery(
|
||||||
|
['prob-change-day-ascending', userId],
|
||||||
|
() =>
|
||||||
|
searchClient
|
||||||
|
.initIndex(getIndexName('prob-change-day-ascending'))
|
||||||
|
.search<CPMMContract>('', {
|
||||||
|
facetFilters: ['uniqueBettorIds:' + userId],
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!positiveData || !negativeData) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
positiveChanges: positiveData.hits,
|
||||||
|
negativeChanges: negativeData.hits,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const useProbChanges = (userId: string) => {
|
export const useProbChanges = (userId: string) => {
|
||||||
const { data: positiveChanges } = useFirestoreQueryData(
|
const { data: positiveChanges } = useFirestoreQueryData(
|
||||||
|
|
|
@ -2,13 +2,13 @@ import { ProbChangeTable } from 'web/components/contract/prob-change-table'
|
||||||
import { Col } from 'web/components/layout/col'
|
import { Col } from 'web/components/layout/col'
|
||||||
import { Page } from 'web/components/page'
|
import { Page } from 'web/components/page'
|
||||||
import { Title } from 'web/components/title'
|
import { Title } from 'web/components/title'
|
||||||
import { useProbChanges } from 'web/hooks/use-prob-changes'
|
import { useProbChangesAlgolia } from 'web/hooks/use-prob-changes'
|
||||||
import { useUser } from 'web/hooks/use-user'
|
import { useUser } from 'web/hooks/use-user'
|
||||||
|
|
||||||
export default function DailyMovers() {
|
export default function DailyMovers() {
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
|
||||||
const changes = useProbChanges(user?.id ?? '')
|
const changes = useProbChangesAlgolia(user?.id ?? '')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
|
|
|
@ -31,7 +31,7 @@ import { ProbChangeTable } from 'web/components/contract/prob-change-table'
|
||||||
import { groupPath, joinGroup, leaveGroup } from 'web/lib/firebase/groups'
|
import { groupPath, joinGroup, leaveGroup } from 'web/lib/firebase/groups'
|
||||||
import { usePortfolioHistory } from 'web/hooks/use-portfolio-history'
|
import { usePortfolioHistory } from 'web/hooks/use-portfolio-history'
|
||||||
import { formatMoney } from 'common/util/format'
|
import { formatMoney } from 'common/util/format'
|
||||||
import { useProbChanges } from 'web/hooks/use-prob-changes'
|
import { useProbChangesAlgolia } from 'web/hooks/use-prob-changes'
|
||||||
import { ProfitBadge } from 'web/components/bets-list'
|
import { ProfitBadge } from 'web/components/bets-list'
|
||||||
import { calculatePortfolioProfit } from 'common/calculate-metrics'
|
import { calculatePortfolioProfit } from 'common/calculate-metrics'
|
||||||
import { hasCompletedStreakToday } from 'web/components/profile/betting-streak-modal'
|
import { hasCompletedStreakToday } from 'web/components/profile/betting-streak-modal'
|
||||||
|
@ -243,7 +243,7 @@ function GroupSection(props: {
|
||||||
|
|
||||||
function DailyMoversSection(props: { userId: string | null | undefined }) {
|
function DailyMoversSection(props: { userId: string | null | undefined }) {
|
||||||
const { userId } = props
|
const { userId } = props
|
||||||
const changes = useProbChanges(userId ?? '')
|
const changes = useProbChangesAlgolia(userId ?? '')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="gap-2">
|
<Col className="gap-2">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user