Skip to content

Commit

Permalink
Add timing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Oct 31, 2024
1 parent 183db1f commit 7fad5e8
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions backend/api/src/on-create-bet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,33 @@ export const onCreateBets = async (result: ExecuteNewBetResult) => {
} = result

const pg = createSupabaseDirectClient()
const startNewBets = Date.now()
broadcastNewBets(contract.id, contract.visibility, bets)
log(`Broadcasting new bets took ${Date.now() - startNewBets}ms`)
if (userUpdates) {
const startUserUpdates = Date.now()
broadcastUserUpdates(userUpdates)
log(`Broadcasting user updates took ${Date.now() - startUserUpdates}ms`)
}
if (contractUpdate) {
const startContractUpdate = Date.now()
broadcastUpdatedContract(contract.visibility, contractUpdate)
log(
`Broadcasting contract update took ${Date.now() - startContractUpdate}ms`
)
}
if (answerUpdates) {
const startAnswerUpdates = Date.now()
broadcastUpdatedAnswers(contract.id, answerUpdates)
log(`Broadcasting answer updates took ${Date.now() - startAnswerUpdates}ms`)
}
if (cancelledLimitOrders) {
const startCancelOrders = Date.now()
broadcastOrders(cancelledLimitOrders)
log(
`Broadcasting cancelled orders took ${Date.now() - startCancelOrders}ms`
)
const startNotifications = Date.now()
await Promise.all(
cancelledLimitOrders.map((order) => {
createLimitBetCanceledNotification(
Expand All @@ -98,6 +114,11 @@ export const onCreateBets = async (result: ExecuteNewBetResult) => {
)
})
)
log(
`Creating limit order cancel notifications took ${
Date.now() - startNotifications
}ms`
)
}
broadcastUpdatedUser(
removeUndefinedProps({
Expand All @@ -108,8 +129,6 @@ export const onCreateBets = async (result: ExecuteNewBetResult) => {
lastBetTime: bets[0].createdTime,
})
)

broadcastNewBets(contract.id, contract.visibility, bets)
const updatedMetrics = reloadMetrics
? await getContractMetrics(pg, [originalBettor.id], contract.id, [], true)
: result.updatedMetrics
Expand Down

0 comments on commit 7fad5e8

Please sign in to comment.