0

Lets say I am persisting movies in a collection with a createdAt property. My android app wants to show all recently added movies in a list by querying this collection with an orderBy statement on the createdAt. I also add a limit 20 at the initial request, and increase this when user scrolls dynamically.

Are these pricing model assumptions correct for these situations:

  1. App is getting started the first time (assumption: 20 read ops because no cached data was available)
  2. App gets closed and opened again. No changes are made in the meanwhile (assumption: 0 read ops since data can get fetched from the cache)
  3. User scrolls. Old snapshot listener gets replaced with a new one where the limit is increased to 40. No changes are made in the meanwhile (assumption: 20 read ops, since there already were 20 known in cache before)
  4. Change is made to db. (assumption: 1 read op)

These assumptions are made based on this stackoverflow post.

But this explanation video (at 8:05) made by the firebase team themselves explains that the case 3 would cost me 40 read ops though. Is this true or is it explained a bit misleading ?

And if the assumptions were correct, how does the library know that there is no need to make new read ops at case 2.?

Ahmet K
  • 713
  • 18
  • 42
  • Besides that Doug's answer, I think that this [resource](https://medium.com/firebase-tips-tricks/how-to-drastically-reduce-the-number-of-reads-when-no-documents-are-changed-in-firestore-8760e2f25e9e) will also help. – Alex Mamo Jun 19 '23 at 08:09
  • I would love to read it but its an "Member-only story". Already saw it in the linked post but I couldn't open it :'( – Ahmet K Jun 19 '23 at 18:39

1 Answers1

2

Is this true or is it explained a bit misleading ?

It is true. When you attach a new listener, it will query for new documents and the query results will not come from cache (unless the app is offline). The cache is primarily in place to handle offline conditions.

how does the library know that there is no need to make new read ops at case 2.?

It doesn't. It does a whole new query.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441