Reputation: 6272
I am implementing Firestore data storage in one of my apps.
I have a listener which follows updates in the "logs" collection like so:
db.collection("logs").addSnapshotListener({ (snapshot, error) in
guard let s = snapshot else {return}
if s.metadata.isFromCache {
print("LOG_C \(s.documentChanges.count)")
return
}
print("LOG \(s.documentChanges.count)")
// other code
})
During testing, I've been uploading documents to this collection and then I removed all of them through Firebase console. So, right now, the collection doesn't exist for my test user. When I launch the app for the first time, I do see that this collection is empty - the listener reports the correct result.
However, in doing so, it consumes roughly 1000 reads. It almost feels like it is downloading all the history of this collection for my test user (e.g. 500 docs inserted, 500 docs deleted). However, even if it does, it does not report it to me - I receive only one "LOG 0" message in the console.
Is this how collection listeners work? I do know that listeners download the initial state, but I thought that it would be the current snapshot which, in this case, would consume 1 read to determine that there is nothing to return initially.
Any explanations/ideas/suggestions are welcome.
I would very much like to debug this by viewing detailed Firestore read logs. However, I cannot find such option in the console :(
Upvotes: 6
Views: 2038
Reputation: 317372
In this case, it sounds as if the OP left the Firestore console open while performing database operations. Since the Firestore console itself reflects realtime updates, it will incur reads over time as the currently selected collection changes.
Upvotes: 6