Reputation: 1943
Hi I have a setup with 30 small documents in Firestore
and on a client side Im using onSnapshot
method to get real time updates. So I end up with 30 onSnapshot
methods - each for every document. Is that a good practice? Is that costly in terms of performance on a client? Is it better to have less onSnapshot
methods in favor of less fragmented documents?
Upvotes: 0
Views: 516
Reputation: 681
This post contain the answer to your question : https://stackoverflow.com/a/50150442/14517101
In the code :
/**
* A PersistentStream that implements the Listen RPC.
*
* Once the Listen stream has called the openHandler, any number of listen and
* unlisten calls calls can be sent to control what changes will be sent from
* the server for ListenResponses.
*/
export class PersistentListenStream extends PersistentStream< // ...
When we create an onSnapshot, the query is sent to the server which remembers what the client is interested in and updates it's notification filter.
This means that we are in scenario #2 and it explains the cost of open connections for the server.
This also means that we do not care how many onSnapshot we create. Concerning the client, there is no performance issue in doing one onSnapshot for each document we get (but there is a Read cost in Firestore for this).
Upvotes: 1