* Store view counts & last viewed time * Schedule updating user recommendations. Compute using tf-idf. * Update contract's lastBetTime and lastCommentTime on new bets and comments. * Remove contract's lastUpdatedTime * Remove folds activity feed * Implement getFeed cloud function * Hook up client to use getFeed * Script to cache viewCounts and lastViewTime * Batched wait all userRecommendations * Cache view script runs on all users * Update user feed each hour and get feed from cache doc. * Delete view cache script * Update feed script * Tweak feed algorithm * Compute recommendation scores from updateUserFeed * Disable lastViewedScore factor * Update lastCommentTime script * Comment out console.log * Fix timeout issue by calling new cloud functions with part of the work. * Listen for contract updates to feed. * Handle new user: use default feed of top markets this week * Track lastUpdatedTime * Tweak logic of calling cloud functions in batches * Tweak cloud function batching
29 lines
811 B
TypeScript
29 lines
811 B
TypeScript
import * as functions from 'firebase-functions'
|
|
import * as admin from 'firebase-admin'
|
|
import * as _ from 'lodash'
|
|
|
|
import { getContract } from './utils'
|
|
import { Bet } from '../../common/bet'
|
|
|
|
const firestore = admin.firestore()
|
|
|
|
export const onCreateBet = functions.firestore
|
|
.document('contracts/{contractId}/bets/{betId}')
|
|
.onCreate(async (change, context) => {
|
|
const { contractId } = context.params as {
|
|
contractId: string
|
|
}
|
|
|
|
const contract = await getContract(contractId)
|
|
if (!contract)
|
|
throw new Error('Could not find contract corresponding with bet')
|
|
|
|
const bet = change.data() as Bet
|
|
const lastBetTime = bet.createdTime
|
|
|
|
await firestore
|
|
.collection('contracts')
|
|
.doc(contract.id)
|
|
.update({ lastBetTime, lastUpdatedTime: Date.now() })
|
|
})
|