问题
I came across the phrase below in Firestore help document which got me confused.
"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."
Does this mean that if I disconnect a listener and connect again within 30 minutes, I won't be charged for reads after connecting listener again? Imagine if I reconnect query and retrieve 20 documents again in (change.type === "added").
db.collection("cities").where("state", "==", "CA") .onSnapshot(function(snapshot) { snapshot.docChanges.forEach(function(change) { //imagine 20 documents are fetched when I listen. if (change.type === "added") { console.log("New city: ", change.doc.data()); } }); });
Am I confused or the phrase is confusing? (or.. have I found a loophole? lol)
回答1:
The issue isn't wither you choose to disconnect the listener and reconnect a new one. The issue is if the listener becomes disconnected through some means out of your control, such as network unavailability.
Think about how expensive your query might be if the user's device is on a very spotty connection whose availability comes and goes frequently. The point is to acknowledge that you shouldn't have to pay for those conditions outside your control.
But if you're just going to repeatedly querying your database, well, you should be paying for that.
来源:https://stackoverflow.com/questions/48481680/firestore-pricing-need-help-understanding-a-phrase-in-the-document