Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Use batch to delete firestore's data in master branch #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,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.delete();
calleeCandidates.forEach(candidate => {
batch.delete(candidate.ref);
});
const callerCandidates = await roomRef.collection('callerCandidates').get();
callerCandidates.forEach(async candidate => {
await candidate.delete();
callerCandidates.forEach(candidate => {
batch.delete(candidate.ref);
});
await roomRef.delete();
batch.delete(roomRef);
await batch.commit();
}

document.location.reload(true);
Expand Down