Skip to content

Commit

Permalink
Remove code to replicate answers from updateContractMetrics (manifo…
Browse files Browse the repository at this point in the history
  • Loading branch information
mqp authored Jan 5, 2024
1 parent 2ee6568 commit 4b214d9
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 57 deletions.
17 changes: 0 additions & 17 deletions backend/shared/src/supabase/answers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SupabaseDirectClient } from 'shared/supabase/init'
import { convertAnswer } from 'common/supabase/contracts'
import { groupBy } from 'lodash'
import { Answer } from 'common/answer'

export const getAnswersForContractsDirect = async (
pg: SupabaseDirectClient,
Expand All @@ -20,19 +19,3 @@ export const getAnswersForContractsDirect = async (
'contractId'
)
}

export const replicateAnswers = async (
pg: SupabaseDirectClient,
answers: Answer[]
) => {
return await Promise.all(
answers.map(async (a) =>
pg.none(
`insert into answers (id, contract_id, data, fs_updated_time)
values ($1, $2, $3, $4)
on conflict (id) do nothing`,
[a.id, a.contractId, a, new Date().toISOString()]
)
)
)
}
40 changes: 0 additions & 40 deletions backend/shared/src/update-contract-metrics-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { computeElasticity } from 'common/calculate-metrics'
import { hasChanges } from 'common/util/object'
import { groupBy, mapValues } from 'lodash'
import { LimitBet } from 'common/bet'
import { filterDefined } from 'common/util/array'
import { replicateAnswers } from 'shared/supabase/answers'

export async function updateContractMetricsCore({ log }: JobContext) {
const firestore = admin.firestore()
Expand All @@ -32,44 +30,6 @@ export async function updateContractMetricsCore({ log }: JobContext) {
const weekAgo = now - WEEK_MS
const monthAgo = now - MONTH_MS

const allContractAnswerIds = answers.map((a) => a.id)
const recentBets = await pg.map(
`select distinct answer_id, contract_id from contract_bets
where created_time >= millis_to_ts($1)
and answer_id is not null
and answer_id != 'undefined'
`,
[now - MONTH_MS * 3],
(r) => ({
answerId: r.answer_id as string,
contractId: r.contract_id as string,
})
)
const recentBetOnAnswerIds = recentBets.map((b) => b.answerId)
const missingAnswerIds = recentBetOnAnswerIds.filter(
(id) => !allContractAnswerIds.includes(id)
)
if (missingAnswerIds.length > 0) {
log(`Missing ${missingAnswerIds.length} answers, fetching from Firebase...`)
const answersFromFirebaseSnap = await Promise.all(
missingAnswerIds.map((id) =>
firestore
.collection(
`contracts/${
recentBets.find((b) => b.answerId === id)?.contractId
}/answersCpmm`
)
.doc(id)
.get()
)
)
const answersFromFirebase = filterDefined(
answersFromFirebaseSnap.map((snap) => snap.data() as Answer)
)
await replicateAnswers(pg, answersFromFirebase)
answers.push(...answersFromFirebase)
}

log('Loading current contract probabilities...')
const currentContractProbs = await getCurrentProbs(pg)
const currentAnswerProbs = Object.fromEntries(
Expand Down

0 comments on commit 4b214d9

Please sign in to comment.