Questions about firestore cache and reads charge

喜你入骨 提交于 2020-06-25 16:53:32

问题


There are my understand how firestore cache and read charge will behave in those scenarios.And I am not sure it's right or not.

If I have 2000 documents in a collection.this collection name "testCollection".those documents won't change , update or delete. My client is android with already enable offline persistence and device is currently online

1.

db.collection("testCollection").onSnapshot(function(doc) {});

2000 reads charged and those document are cached. then reopen app and run same code again

db.collection("testCollection").onSnapshot(function(doc) {});

another 2000 reads charged cause firestore need to check each document is up to date or not. So 2000+2000 reads charged

2.

I am not sure how this behave. just run the same code together

db.collection("testCollection").onSnapshot(function(doc) {}); 
db.collection("testCollection").onSnapshot(function(doc) {});

I think is 2000 reads charged because data is keeping up to date

3.

db.collection("testCollection").limit(300).onSnapshot(function(doc) {}); 
db.collection("testCollection").limit(800).onSnapshot(function(doc) {}); 

Total 1100 reads charged.cause it's different query.

Do I have something misunderstand or something wrong ?


回答1:


2000 reads charged and those documents are cached.

That's correct since it's the first time when you perform those read operations.

another 2000 reads charged cause Firestore needs to check each document is up to date or not. So 2000+2000 reads charged

Once the documents are in your cache and those documents aren't changed (as you say), all read operations are coming from the cache. You won't be charged for read operations that are coming from the cache.

I think is 2000 reads charged because data is keeping up to date

You'll be charged with other read operations only if the data on the Firebase servers is changed, otherwise, you'll get the data from the cache.

Total 1100 reads charged.cause it's a different query

If you have already performed the initial query and you already got those 2000 documents, if you perform another query no matter if you are using a limit or not, you read all those documents from the cache.



来源:https://stackoverflow.com/questions/56617814/questions-about-firestore-cache-and-reads-charge

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