emreoktem
emreoktem

Reputation: 2547

First query snapshot of snapshotListener

According to the Firebase - Firestore documentation, snapshotListeners provides all of the available records when we enabled the listener based on our query.

Firestore documentation:

The first query snapshot contains added events for all existing documents that match the query. This is because you're getting a set of changes that bring your query snapshot current with the initial state of the query. This allows you, for instance, to directly populate your UI from the changes you receive in the first query snapshot, without needing to add special logic for handling the initial state.

As far as I understood, it's not possible to disable this feature but there are some workarounds.

My question is if this behavior counts as one read for every record received during the first initialization or not?

Upvotes: 1

Views: 543

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83058

My question is if this behavior counts as one read for every record received during the first initialization or not?

The answer is yes: the "initial state of the query" implies that all documents corresponding to the query are read.


However, as explained in the documentation:

The initial state can come from the server directly, or from a local cache. If there is state available in a local cache, the query snapshot will be initially populated with the cached data.

If the initial state comes from a local cache (See offline data persistence), it will not count for any read.

Upvotes: 1

Related Questions