Kill warmup spam (#133)

* Only warm up sell bet function once

* Only warm up create user function once
This commit is contained in:
Marshall Polaris 2022-05-05 09:51:09 -07:00 committed by GitHub
parent adefd3259c
commit 2e214cab7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -553,10 +553,11 @@ function BetRow(props: { bet: Bet; contract: Contract; saleBet?: Bet }) {
) )
} }
const warmUpSellBet = _.throttle(() => sellBet({}).catch(), 5000 /* ms */)
function SellButton(props: { contract: Contract; bet: Bet }) { function SellButton(props: { contract: Contract; bet: Bet }) {
useEffect(() => { useEffect(() => {
// warm up cloud function warmUpSellBet()
sellBet({}).catch()
}, []) }, [])
const { contract, bet } = props const { contract, bet } = props

View File

@ -77,11 +77,13 @@ const CACHED_USER_KEY = 'CACHED_USER_KEY'
// used to avoid weird race condition // used to avoid weird race condition
let createUserPromise: Promise<User | null> | undefined = undefined let createUserPromise: Promise<User | null> | undefined = undefined
const warmUpCreateUser = _.throttle(createUser, 5000 /* ms */)
export function listenForLogin(onUser: (user: User | null) => void) { export function listenForLogin(onUser: (user: User | null) => void) {
const cachedUser = localStorage.getItem(CACHED_USER_KEY) const cachedUser = localStorage.getItem(CACHED_USER_KEY)
onUser(cachedUser ? JSON.parse(cachedUser) : null) onUser(cachedUser ? JSON.parse(cachedUser) : null)
if (!cachedUser) createUser() // warm up cloud function if (!cachedUser) warmUpCreateUser()
return onAuthStateChanged(auth, async (fbUser) => { return onAuthStateChanged(auth, async (fbUser) => {
if (fbUser) { if (fbUser) {