From 5df208aba9e16cf143a57e7eb17f72e5589e563a Mon Sep 17 00:00:00 2001 From: juniorpires Date: Sat, 4 Aug 2018 12:58:41 -0300 Subject: [PATCH] Change deleteAll to use batch-like style --- entity/entity.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/entity/entity.ts b/entity/entity.ts index a0c4670..20c19c9 100644 --- a/entity/entity.ts +++ b/entity/entity.ts @@ -282,22 +282,24 @@ export class Entity { if (collectionName == undefined) collectionName = this.className() + let collection: AngularFirestoreCollection = fireStore.collection(collectionName); - this.getAll(fireStore, collectionName).subscribe(result => { - let documents = []; + collection.ref.get().then( list =>{ - for (let i = 0; i < result.length; i++) { - documents.push(result[i].delete(collectionName)); - } + const batch = fireStore.firestore.batch(); + + list.forEach( doc => { + batch.delete(doc.ref) + }) - Promise.all(documents).then(result => { + batch.commit().then(() => { observer.next(); observer.complete(); }); - }, err => { - observer.error(err); - }) + },err => { + observer.error(err); + }) }); }