Do I read all documents again if there is a change in the Firestore database?

ぃ、小莉子 提交于 2020-01-30 10:35:12

问题


let say I try to get a list of eventID that liked by the user by using Firestore listener. I also use offline persistence.

from this thread : Firestore - Using cache until online content updates

I know that the listener will be fired immediately with the results from the cache and if there is a change result, I will get another snapshot with the changes.

in swift, the reference to get the list is:

FirestoreDocumentReference.users(uidUser: uid).reference().collection("likedEvents").addSnapshotListener({ (snapshot, error) in )}

let say at first in the firestore database I have 100 eventID that liked by the user, and then the user like another 50 event, it means I have 150 liked eventID in the database now.

since there is a change in the database from 100 to 150, Firestore will check with the server right? and it will give me another snapshot.

my question is ....

Do I read 150 documents or just 50 documents after receiving new snapshot from firestore? I mean, Do I read all documents again or just changed document?

because read operation will affect the pricing of firestore


回答1:


Just 50 :-)
https://firebase.google.com/docs/firestore/pricing#listens

you are charged for a read each time a document in the result set is added or updated




回答2:


The answer here is it depends.

When open a new snapshot listener with Firestore you get something called a "resume token" which you can think of like a session. A resume token helps the server try and send you only the documents that have changed since the last snapshot you received. However these tokens expire in <= 30 minutes. So it depends on how long the 50 new documents are added after you initialize your snapshot listener.



来源:https://stackoverflow.com/questions/50782574/do-i-read-all-documents-again-if-there-is-a-change-in-the-firestore-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!