67d0a6c0c2
* Create Top Followed Users leaderboard * Switch to increment/decrement approach for caching user follower counts * Backfill script for user follow counts * Appease ESLint * Address review comment Co-authored-by: James Grugett <jahooma@gmail.com>
19 lines
539 B
TypeScript
19 lines
539 B
TypeScript
import * as functions from 'firebase-functions'
|
|
import * as admin from 'firebase-admin'
|
|
|
|
import { FieldValue } from 'firebase-admin/firestore'
|
|
|
|
export const onUnfollowUser = functions.firestore
|
|
.document('users/{userId}/follows/{followedUserId}')
|
|
.onDelete(async (change, context) => {
|
|
const { followedUserId } = context.params as {
|
|
followedUserId: string
|
|
}
|
|
|
|
await firestore.doc(`users/${followedUserId}`).update({
|
|
followerCountCached: FieldValue.increment(-1),
|
|
})
|
|
})
|
|
|
|
const firestore = admin.firestore()
|