Fix feed to actually sort by last bet
This commit is contained in:
parent
ab5ea0181d
commit
a3592f388b
|
@ -23,7 +23,7 @@ function lastActivityTime(contract: Contract) {
|
||||||
// - Comment on a market
|
// - Comment on a market
|
||||||
// - New market created
|
// - New market created
|
||||||
// - Market resolved
|
// - Market resolved
|
||||||
// - Markets with most betting in last 24 hours
|
// - Bet on market
|
||||||
export function findActiveContracts(
|
export function findActiveContracts(
|
||||||
allContracts: Contract[],
|
allContracts: Contract[],
|
||||||
recentComments: Comment[],
|
recentComments: Comment[],
|
||||||
|
@ -36,23 +36,17 @@ export function findActiveContracts(
|
||||||
idToActivityTime.set(contractId, Math.max(oldTime ?? 0, time))
|
idToActivityTime.set(contractId, Math.max(oldTime ?? 0, time))
|
||||||
}
|
}
|
||||||
|
|
||||||
let contracts: Contract[] = []
|
const contractsById = new Map(allContracts.map((c) => [c.id, c]))
|
||||||
|
|
||||||
// Find contracts with activity in the last 3 days
|
// Record contract activity.
|
||||||
const DAY_IN_MS = 24 * 60 * 60 * 1000
|
for (const contract of allContracts) {
|
||||||
for (const contract of allContracts || []) {
|
|
||||||
contracts.push(contract)
|
|
||||||
record(contract.id, lastActivityTime(contract))
|
record(contract.id, lastActivityTime(contract))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add every contract that had a recent comment, too
|
// Add every contract that had a recent comment, too
|
||||||
const contractsById = new Map(allContracts.map((c) => [c.id, c]))
|
|
||||||
for (const comment of recentComments) {
|
for (const comment of recentComments) {
|
||||||
const contract = contractsById.get(comment.contractId)
|
const contract = contractsById.get(comment.contractId)
|
||||||
if (contract) {
|
if (contract) record(contract.id, comment.createdTime)
|
||||||
contracts.push(contract)
|
|
||||||
record(contract.id, comment.createdTime)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add contracts by last bet time.
|
// Add contracts by last bet time.
|
||||||
|
@ -62,19 +56,18 @@ export function findActiveContracts(
|
||||||
(bets) => _.maxBy(bets, (bet) => bet.createdTime) as Bet
|
(bets) => _.maxBy(bets, (bet) => bet.createdTime) as Bet
|
||||||
)
|
)
|
||||||
for (const bet of Object.values(contractMostRecentBet)) {
|
for (const bet of Object.values(contractMostRecentBet)) {
|
||||||
const contract = contractsById.get(bet.id)
|
const contract = contractsById.get(bet.contractId)
|
||||||
if (contract) {
|
if (contract) record(contract.id, bet.createdTime)
|
||||||
contracts.push(contract)
|
|
||||||
record(contract.id, bet.createdTime)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contracts = _.uniqBy(contracts, (c) => c.id)
|
let activeContracts = allContracts.filter(
|
||||||
contracts = contracts.filter(
|
|
||||||
(contract) => contract.visibility === 'public' && !contract.isResolved
|
(contract) => contract.visibility === 'public' && !contract.isResolved
|
||||||
)
|
)
|
||||||
contracts = _.sortBy(contracts, (c) => -(idToActivityTime.get(c.id) ?? 0))
|
activeContracts = _.sortBy(
|
||||||
return contracts.slice(0, MAX_ACTIVE_CONTRACTS)
|
activeContracts,
|
||||||
|
(c) => -(idToActivityTime.get(c.id) ?? 0)
|
||||||
|
)
|
||||||
|
return activeContracts.slice(0, MAX_ACTIVE_CONTRACTS)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ActivityFeed(props: {
|
export function ActivityFeed(props: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user