简体   繁体   English

Firestore监听机制效率

[英]Firestore listener mechanism efficiency

If I understand correctly, in the initialization phase of addSnapshotListener you get a list of all the documents (even if it is 500 trillion documents) from the QuerySnapshot if you call the getDocuments function. Then, every time you modify or add a document to a collection, you get from QuerySnapshot all the documents that have been modified by calling the getDocumentChanges function or all the existing documents by calling getDocuments .如果我理解正确,在addSnapshotListener的初始化阶段,如果您调用getDocuments function,您会从 QuerySnapshot 获得所有文档(即使是 500 万亿个文档)的列表。然后,每次修改或添加文档到集合,您可以从QuerySnapshot获取所有已通过调用getDocumentChanges function 修改的文档或通过调用getDocuments获取所有现有文档。

That means both at the initialization stage and after every change, I always get a list of all the documents.这意味着在初始化阶段和每次更改后,我总是会得到所有文档的列表。 That's logical?这符合逻辑吗? Assuming I have 500 trillion documents under the same collection (just for the sake of exaggeration), at every change and initialization of the app will I get them all?假设我在同一个集合下有 500 万亿个文档(只是为了夸张),在应用程序的每次更改和初始化时,我都会得到它们吗?

Is that really the case?真的是这样吗? Or is it some kind of lazy instantiation or something?还是某种惰性实例化之类的? Because if so, when I would like to question the whole collection, no matter what I get at first the whole list?因为如果是这样,当我想质疑整个集合时,不管我一开始得到的是什么?

The QuerySnapshot always contains all documents that match the query (or collection reference). QuerySnapshot始终包含与查询(或集合引用)匹配的所有文档。 Even when there's an update and only a subset of the documents matched by the query is changed, the QuerySnapshot still contains all of the documents, even though in its communication between the SDK and the backend serves, Firestore only synchronizes the modified documents.即使有更新并且只有与查询匹配的文档的子集发生更改, QuerySnapshot仍包含所有文档,即使在 SDK 与后端服务之间的通信中,Firestore 仅同步修改后的文档。 If you only want to process the changes, you can process just the changes between the snapshots .如果你只想处理变化,你可以只处理快照之间的变化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM