Home > Back-end >  What does count as a brand-new query in Firestore snapshot listener?
What does count as a brand-new query in Firestore snapshot listener?

Time:07-22

When using a snapshot listener on documents, we are charged for reads on each change. That is well understood.

However, in the docs on billing, there is written:

Also, if the listener is disconnected for more than 30 minutes (for example, if the user goes offline), you will be charged for reads as if you had issued a brand-new query.

What does "disconnected" mean in the web context? I have never understood the quote.

Let's have a listener on 30 documents. I load a web page, fetch 30 documents via snapshot listener for which I am billed 30 reads. Then I hit the F5 key and refresh the page. Is this a brand-new query and am I billed 30 reads again, or am I reusing the previous snapshot query and have the second round of reads for free?

CodePudding user response:

What does "disconnected" mean in the web context?

Disconnection means the same thing for any client platform. It's the situation when the device running the code loses its connection to the internet for whatever reason. The usual expectation is that the client will regain the connection later, and the Firestore SDK is able to automatically reconnect to the backend and re-establish any listeners that were active when the connection went away.

Then I hit the F5 key and refresh the page. Is this a brand-new query and am I billed 30 reads again?

Yes, a page reload is not a lost connection. It's a whole new page context with new code running that establishes a new connection. In-memory data (such as active listeners) is not retained in the case of a page reload. The browser simply wipes all of that out and starts fresh.

  • Related