From e76ab5e42696caa8ef7dc667918bc6eaea729d16 Mon Sep 17 00:00:00 2001 From: t104360088 Date: Thu, 25 Mar 2021 11:40:04 +0800 Subject: [PATCH] Use batch to delete firestore's data --- public/app.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/public/app.js b/public/app.js index 4e3b4d6..6fa8ac6 100644 --- a/public/app.js +++ b/public/app.js @@ -224,16 +224,18 @@ async function hangUp(e) { // Delete room on hangup if (roomId) { const db = firebase.firestore(); + const batch = db.batch(); const roomRef = db.collection('rooms').doc(roomId); const calleeCandidates = await roomRef.collection('calleeCandidates').get(); - calleeCandidates.forEach(async candidate => { - await candidate.ref.delete(); + calleeCandidates.forEach(candidate => { + batch.delete(candidate.ref); }); const callerCandidates = await roomRef.collection('callerCandidates').get(); - callerCandidates.forEach(async candidate => { - await candidate.ref.delete(); + callerCandidates.forEach(candidate => { + batch.delete(candidate.ref); }); - await roomRef.delete(); + batch.delete(roomRef); + await batch.commit(); } document.location.reload(true);