Skip to content

Commit

Permalink
for.of instead of foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Dec 11, 2024
1 parent e8811ac commit 31cd181
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions infra/dataform-export/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,22 @@ export class FirestoreBatch {
}

while (true) {
const snapshot = await collectionQuery.limit(100000).get()
const snapshot = await collectionQuery.limit(this.batchSize * this.maxConcurrentBatches).get()
if (snapshot.empty) {
break
}

snapshot.forEach(async (doc) => {
for await (const doc of snapshot.docs) {
this.currentBatch.push(doc)

if (this.currentBatch.length >= this.batchSize) {
this.queueBatch('delete')
}

if (this.batchPromises.length >= this.maxConcurrentBatches) {
await this.commitBatches()
}
totalDocsDeleted++
})
}
}
await this.finalFlush('delete')

Expand Down

0 comments on commit 31cd181

Please sign in to comment.