- I am using the firebase JS SDK, with offline persistence enabled. This will automatically cache my retrieved documents inside the JS SDK.
- I perform this query:
// once
firebase.firestore().doc('path/to/doc').get()
// twice
firebase.firestore().doc('path/to/doc').get()
My questions are:
- Would Firebase charge me for two reads in the case offline persistence is enabled. Since I believe the second read would come from the offline cache without making a network call?
- Would Firebase charge me once or twice when offline persistence is disabled?
My use case
A user opens a web-app with his 'tasks' from clients.
Each task has a client field with a document reference.
- retrieve all tasks (eg. 500 reads)
- retrieve each client document per task (another 500 reads even though some clients are the same)
So if there are only say 20 clients, I'd rather have only 520 reads instead of 1000 reads when the user opens the app.
Is it better to redesign my data structure to have the relevant client information saved on the task itself instead of a reference, or will the Firebase JS SDK be smart enough to not double retrieve the same doc it just retrieved.
PS: I found a similar question here:
Does Firestore charge Cloud Function Get reads per retrieved documents?
But it just didn't have the exact information I was looking for.