-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Batch deletes trigger multiple observer callbacks instead of one #5955
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
Comments
@alexookah I've tried reproducing your issue in tests by deleting multiple documents using If so, can you provide a repro, or enable verbose logging and share the logs from a local reproduction? |
@thebrianchen The batched delete is done in a cloud function using something like this:
and additions / modifications use similar code (the iOS only reads the data). |
@thebrianchen Using the Simulator the document deletions appear one by one, but using a real device (iPad), they come in small batches (20-50 documents) instead of 500 which is the batch size. For additions and modifications, both the simulator and the real device receive batches of 500 changes. |
@alexookah I tried reproducing it locally in a query with many documents and used a batch size of 500 without success. Could you enable verbose logging and share the logs from the batch deletes? Thanks! |
Here are the verbose logs (zip file) and this is my code:
|
Thanks for taking the time to record and share the logs with us! From the logs, it appears the multiple snapshots you are receiving are a consequence of the limbo resolution performed by the Firestore client. The 500 documents in the batch you deleted were marked as “removed” rather than “deleted” by the Firestore backend, which prompted the client to mark them as being in limbo. The client resolves the limbo documents by looking them up in batches, to avoid overloading the backend. Firestore raises a snapshot callback each time a batch is complete, which results in the multiple callbacks you are observing. To tell which snapshot contains the guaranteed up-to-date server snapshot, you can include metadata changes in your snapshot listener and filter out any snapshots that have the isFromCache property set to As for the 100% CPU usage by |
Closing since this is working as intended. |
Uh oh!
There was an error while loading. Please reload this page.
[REQUIRED] Step 1: Describe your environment
[REQUIRED] Step 2: Describe the problem
When observing a whereFilter query, when multiple documents are deleted, the observer callback is called once for every deleted document, instead of being called once with multiple document changes (like additions and modifications do).
The performance of these callbacks is also very poor (OnWatchStreamChange uses 100% cpu).
Observing a whole collection (without a whereFilter) seems to be okay.
Steps to reproduce:
Observe a query that has many documents, then delete multiple documents (using a different device).
The observer callback will be run multiple times, once for each deleted document.
Relevant Code:
The text was updated successfully, but these errors were encountered: