Skip to content

Firestore: QueryTest.java: Use a WriteBatch to delete documents rather than a transaction #5167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1068,21 +1068,18 @@ public void resumingAQueryShouldUseBloomFilterToAvoidFullRequery() throws Except
}
assertWithMessage("createdDocuments").that(createdDocuments).hasSize(100);

// Delete 50 of the 100 documents. Do this in a transaction, rather than
// DocumentReference.delete(), to avoid affecting the local cache.
// Delete 50 of the 100 documents. Use a WriteBatch, rather than DocumentReference.delete(),
// to avoid affecting the local cache.
HashSet<String> deletedDocumentIds = new HashSet<>();
waitFor(
collection
.getFirestore()
.runTransaction(
transaction -> {
for (int i = 0; i < createdDocuments.size(); i += 2) {
DocumentReference documentToDelete = createdDocuments.get(i);
transaction.delete(documentToDelete);
deletedDocumentIds.add(documentToDelete.getId());
}
return null;
}));
{
WriteBatch writeBatchForDocumentDeletes = collection.getFirestore().batch();
for (int i = 0; i < createdDocuments.size(); i += 2) {
DocumentReference documentToDelete = createdDocuments.get(i);
writeBatchForDocumentDeletes.delete(documentToDelete);
deletedDocumentIds.add(documentToDelete.getId());
}
waitFor(writeBatchForDocumentDeletes.commit());
}
assertWithMessage("deletedDocumentIds").that(deletedDocumentIds).hasSize(50);

// Wait for 10 seconds, during which Watch will stop tracking the query and will send an
Expand Down Expand Up @@ -1240,22 +1237,15 @@ public void bloomFilterShouldCorrectlyEncodeComplexUnicodeCharacters() throws Ex
.containsExactlyElementsIn(testDocIds);
}

// Delete one of the documents so that the next call to getDocs() will experience an existence
// filter mismatch. Do this deletion in a transaction, rather than using deleteDoc(), to avoid
// Delete one of the documents so that the next call to collection.get() will experience an
// existence filter mismatch. Use a WriteBatch, rather than DocumentReference.delete(), to avoid
// affecting the local cache.
DocumentReference documentToDelete = collection.document("DocumentToDelete");
waitFor(
collection
.getFirestore()
.runTransaction(
transaction -> {
DocumentSnapshot documentToDeleteSnapshot = transaction.get(documentToDelete);
assertWithMessage("documentToDeleteSnapshot.exists()")
.that(documentToDeleteSnapshot.exists())
.isTrue();
transaction.delete(documentToDelete);
return null;
}));
{
WriteBatch writeBatchForDocumentDeletes = collection.getFirestore().batch();
writeBatchForDocumentDeletes.delete(documentToDelete);
waitFor(writeBatchForDocumentDeletes.commit());
}

// Wait for 10 seconds, during which Watch will stop tracking the query and will send an
// existence filter rather than "delete" events when the query is resumed.
Expand Down