Skip to content

Commit 6b1be2a

Browse files
authored
Firestore: query.test.ts: Use a WriteBatch to delete documents rather than a transaction (#7415)
1 parent 5825aaf commit 6b1be2a

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

packages/firestore/test/integration/api/query.test.ts

+13-22
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
Query,
4949
query,
5050
QuerySnapshot,
51-
runTransaction,
5251
setDoc,
5352
startAfter,
5453
startAt,
@@ -2096,16 +2095,16 @@ apiDescribe('Queries', persistence => {
20962095
expect(snapshot1.size, 'snapshot1.size').to.equal(100);
20972096
const createdDocuments = snapshot1.docs.map(snapshot => snapshot.ref);
20982097

2099-
// Delete 50 of the 100 documents. Do this in a transaction, rather than
2098+
// Delete 50 of the 100 documents. Use a WriteBatch, rather than
21002099
// deleteDoc(), to avoid affecting the local cache.
21012100
const deletedDocumentIds = new Set<string>();
2102-
await runTransaction(db, async txn => {
2103-
for (let i = 0; i < createdDocuments.length; i += 2) {
2104-
const documentToDelete = createdDocuments[i];
2105-
txn.delete(documentToDelete);
2106-
deletedDocumentIds.add(documentToDelete.id);
2107-
}
2108-
});
2101+
const writeBatchForDocumentDeletes = writeBatch(db);
2102+
for (let i = 0; i < createdDocuments.length; i += 2) {
2103+
const documentToDelete = createdDocuments[i];
2104+
writeBatchForDocumentDeletes.delete(documentToDelete);
2105+
deletedDocumentIds.add(documentToDelete.id);
2106+
}
2107+
await writeBatchForDocumentDeletes.commit();
21092108

21102109
// Wait for 10 seconds, during which Watch will stop tracking the query
21112110
// and will send an existence filter rather than "delete" events when
@@ -2260,19 +2259,11 @@ apiDescribe('Queries', persistence => {
22602259
);
22612260

22622261
// Delete one of the documents so that the next call to getDocs() will
2263-
// experience an existence filter mismatch. Do this deletion in a
2264-
// transaction, rather than using deleteDoc(), to avoid affecting the
2265-
// local cache.
2266-
await runTransaction(db, async txn => {
2267-
const snapshotOfDocumentToDelete = await txn.get(
2268-
doc(coll, 'DocumentToDelete')
2269-
);
2270-
expect(
2271-
snapshotOfDocumentToDelete.exists(),
2272-
'snapshotOfDocumentToDelete.exists()'
2273-
).to.be.true;
2274-
txn.delete(snapshotOfDocumentToDelete.ref);
2275-
});
2262+
// experience an existence filter mismatch. Use a WriteBatch, rather
2263+
// than deleteDoc(), to avoid affecting the local cache.
2264+
const writeBatchForDocumentDeletes = writeBatch(db);
2265+
writeBatchForDocumentDeletes.delete(doc(coll, 'DocumentToDelete'));
2266+
await writeBatchForDocumentDeletes.commit();
22762267

22772268
// Wait for 10 seconds, during which Watch will stop tracking the query
22782269
// and will send an existence filter rather than "delete" events when

0 commit comments

Comments
 (0)