Fetch somewhat less data for fold static props
This commit is contained in:
parent
6243f132aa
commit
ce30b34480
|
@ -5,12 +5,7 @@ import { Fold } from '../../../../common/fold'
|
||||||
import { Comment } from '../../../../common/comment'
|
import { Comment } from '../../../../common/comment'
|
||||||
import { Page } from '../../../components/page'
|
import { Page } from '../../../components/page'
|
||||||
import { Title } from '../../../components/title'
|
import { Title } from '../../../components/title'
|
||||||
import {
|
import { Bet, listAllBets } from '../../../lib/firebase/bets'
|
||||||
Bet,
|
|
||||||
getRecentContractBets,
|
|
||||||
listAllBets,
|
|
||||||
} from '../../../lib/firebase/bets'
|
|
||||||
import { listAllComments } from '../../../lib/firebase/comments'
|
|
||||||
import { Contract } from '../../../lib/firebase/contracts'
|
import { Contract } from '../../../lib/firebase/contracts'
|
||||||
import {
|
import {
|
||||||
foldPath,
|
foldPath,
|
||||||
|
@ -50,41 +45,21 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) {
|
||||||
|
|
||||||
const contracts = fold ? await getFoldContracts(fold).catch((_) => []) : []
|
const contracts = fold ? await getFoldContracts(fold).catch((_) => []) : []
|
||||||
|
|
||||||
const betsPromise = Promise.all(
|
const bets = await Promise.all(
|
||||||
contracts.map((contract) => listAllBets(contract.id))
|
contracts.map((contract) => listAllBets(contract.id))
|
||||||
)
|
)
|
||||||
|
const betsByContract = _.fromPairs(contracts.map((c, i) => [c.id, bets[i]]))
|
||||||
|
|
||||||
const [contractComments, contractRecentBets] = await Promise.all([
|
let activeContracts = findActiveContracts(contracts, [], _.flatten(bets))
|
||||||
Promise.all(
|
|
||||||
contracts.map((contract) => listAllComments(contract.id).catch((_) => []))
|
|
||||||
),
|
|
||||||
Promise.all(
|
|
||||||
contracts.map((contract) =>
|
|
||||||
getRecentContractBets(contract.id).catch((_) => [])
|
|
||||||
)
|
|
||||||
),
|
|
||||||
])
|
|
||||||
|
|
||||||
let activeContracts = findActiveContracts(
|
|
||||||
contracts,
|
|
||||||
_.flatten(contractComments),
|
|
||||||
_.flatten(contractRecentBets)
|
|
||||||
)
|
|
||||||
const [resolved, unresolved] = _.partition(
|
const [resolved, unresolved] = _.partition(
|
||||||
activeContracts,
|
activeContracts,
|
||||||
({ isResolved }) => isResolved
|
({ isResolved }) => isResolved
|
||||||
)
|
)
|
||||||
activeContracts = [...unresolved, ...resolved]
|
activeContracts = [...unresolved, ...resolved]
|
||||||
|
|
||||||
const activeContractBets = await Promise.all(
|
const activeContractBets = activeContracts.map(
|
||||||
activeContracts.map((contract) => listAllBets(contract.id).catch((_) => []))
|
(contract) => betsByContract[contract.id] ?? []
|
||||||
)
|
)
|
||||||
const activeContractComments = activeContracts.map(
|
|
||||||
(contract) =>
|
|
||||||
contractComments[contracts.findIndex((c) => c.id === contract.id)]
|
|
||||||
)
|
|
||||||
|
|
||||||
const bets = await betsPromise
|
|
||||||
|
|
||||||
const creatorScores = scoreCreators(contracts, bets)
|
const creatorScores = scoreCreators(contracts, bets)
|
||||||
const traderScores = scoreTraders(contracts, bets)
|
const traderScores = scoreTraders(contracts, bets)
|
||||||
|
@ -102,7 +77,7 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) {
|
||||||
contracts,
|
contracts,
|
||||||
activeContracts,
|
activeContracts,
|
||||||
activeContractBets,
|
activeContractBets,
|
||||||
activeContractComments,
|
activeContractComments: activeContracts.map(() => []),
|
||||||
traderScores,
|
traderScores,
|
||||||
topTraders,
|
topTraders,
|
||||||
creatorScores,
|
creatorScores,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user