From e3e80a5fd0f17e73a2d6fc16bfb25e33ab765526 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Thu, 8 Sep 2022 20:21:29 -0700 Subject: [PATCH 1/2] Change user info using bulkWriter --- functions/src/change-user-info.ts | 74 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/functions/src/change-user-info.ts b/functions/src/change-user-info.ts index aa041856..ca66f1ba 100644 --- a/functions/src/change-user-info.ts +++ b/functions/src/change-user-info.ts @@ -37,6 +37,45 @@ export const changeUser = async ( avatarUrl?: string } ) => { + // Update contracts, comments, and answers outside of a transaction to avoid contention. + // Using bulkWriter to supports >500 writes at a time + const contractsRef = firestore + .collection('contracts') + .where('creatorId', '==', user.id) + + const contracts = await contractsRef.get() + + const contractUpdate: Partial = removeUndefinedProps({ + creatorName: update.name, + creatorUsername: update.username, + creatorAvatarUrl: update.avatarUrl, + }) + + const commentSnap = await firestore + .collectionGroup('comments') + .where('userUsername', '==', user.username) + .get() + + const commentUpdate: Partial = removeUndefinedProps({ + userName: update.name, + userUsername: update.username, + userAvatarUrl: update.avatarUrl, + }) + + const answerSnap = await firestore + .collectionGroup('answers') + .where('username', '==', user.username) + .get() + const answerUpdate: Partial = removeUndefinedProps(update) + + const bulkWriter = firestore.bulkWriter() + commentSnap.docs.forEach((d) => bulkWriter.update(d.ref, commentUpdate)) + answerSnap.docs.forEach((d) => bulkWriter.update(d.ref, answerUpdate)) + contracts.docs.forEach((d) => bulkWriter.update(d.ref, contractUpdate)) + await bulkWriter.flush() + console.log('Done writing!') + + // Update the username inside a transaction return await firestore.runTransaction(async (transaction) => { if (update.username) { update.username = cleanUsername(update.username) @@ -58,42 +97,7 @@ export const changeUser = async ( const userRef = firestore.collection('users').doc(user.id) const userUpdate: Partial = removeUndefinedProps(update) - - const contractsRef = firestore - .collection('contracts') - .where('creatorId', '==', user.id) - - const contracts = await transaction.get(contractsRef) - - const contractUpdate: Partial = removeUndefinedProps({ - creatorName: update.name, - creatorUsername: update.username, - creatorAvatarUrl: update.avatarUrl, - }) - - const commentSnap = await transaction.get( - firestore - .collectionGroup('comments') - .where('userUsername', '==', user.username) - ) - - const commentUpdate: Partial = removeUndefinedProps({ - userName: update.name, - userUsername: update.username, - userAvatarUrl: update.avatarUrl, - }) - - const answerSnap = await transaction.get( - firestore - .collectionGroup('answers') - .where('username', '==', user.username) - ) - const answerUpdate: Partial = removeUndefinedProps(update) - transaction.update(userRef, userUpdate) - commentSnap.docs.forEach((d) => transaction.update(d.ref, commentUpdate)) - answerSnap.docs.forEach((d) => transaction.update(d.ref, answerUpdate)) - contracts.docs.forEach((d) => transaction.update(d.ref, contractUpdate)) }) } From 677b20a7bafac6e79b0a233c6f5ddb46e60169cb Mon Sep 17 00:00:00 2001 From: marsteralex Date: Thu, 8 Sep 2022 20:23:31 -0700 Subject: [PATCH 2/2] fix brawl commanders for digital (#862) * fix https * add beasts * Remove extra file * Prettier-ify code * Prettier-ify * add basic land guesser also added fetcher to filter all cards instead of only unique art * default to original makes basic better * added set symbol to basics added set symbol to the basics game mode. Changed name to "How Basic" * cleanup * changed some pixels * only load set data if needed * hacked fix for removing image from name * removed check from original * remove check from original * sort names by set instead of by set symbol * include battlebond * update cards for categories update for dominaria united * added commander category commander category * update basic land art * can use double feature * removing racist cards upstream this way we don't have to store the cards in the json * remove generated cards from digital commanders * fix counterspell setting default Co-authored-by: Austin Chen --- web/public/mtg/importCards.py | 2 +- web/public/mtg/index.html | 7 ++----- web/public/mtg/jsons/commander.json | 2 +- web/public/mtg/jsons/set.json | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/web/public/mtg/importCards.py b/web/public/mtg/importCards.py index 17a5e2c2..6d45bd7a 100644 --- a/web/public/mtg/importCards.py +++ b/web/public/mtg/importCards.py @@ -24,7 +24,7 @@ def generate_initial_query(category): '.*player%28%5C.%7C+or+planeswalker%29%7C.*opponent%28%5C.%7C+or+planeswalker%29%29%2F%29' \ '+%28type%3Ainstant+or+type%3Asorcery%29+not%3Aadventure' elif category == 'commander': - string_query += '-banned%3Acommander+is%3Acommander' + string_query += 'is%3Acommander+%28not%3Adigital+-banned%3Acommander+or+is%3Adigital+legal%3Ahistoricbrawl+or+legal%3Acommander+or+legal%3Abrawl%29' # add category string query here string_query += '+-%28set%3Asld+%28%28cn>%3D231+cn<%3D233%29+or+%28cn>%3D321+cn<%3D324%29+or+%28cn>%3D185+cn' \ '<%3D189%29+or+%28cn>%3D138+cn<%3D142%29+or+%28cn>%3D364+cn<%3D368%29+or+cn%3A669+or+cn%3A670%29' \ diff --git a/web/public/mtg/index.html b/web/public/mtg/index.html index bfb324c1..15599eee 100644 --- a/web/public/mtg/index.html +++ b/web/public/mtg/index.html @@ -138,13 +138,10 @@ id="counterspell" name="whichguesser" value="counterspell" + onchange="updateSettingDefault(true, true, false)" checked /> -