问题描述
我想知道,Firestore如何处理深层嵌套对象的实时同步?具体来说,它仅同步差异吗?
I was wondering, how does Firestore handle real-time syncing of deeply nested objects? Specifically, does it only sync the diff?
例如,我有一个应用程序状态,它只是3个值的数组,并且该状态在设备之间同步.如果然后更改其中一个值,则将同步整个新阵列(在网络上传输)还是仅同步差异?如果我的状态是嵌套对象怎么办?
For example, I have a state of the app which is just an array of 3 values and this state is synced between devices. If I then change one of the values will the whole new array be synced (transmitted on the network) or only the diff? What if my state is the nested object?
我之所以问是因为我想同步具有多个字段的对象的整个状态,但是当我只更改单个字段时,我不会同步整个对象.
I'm asking because I want to sync the whole state which is an object with multiple fields but I don't wont to sync the whole object when I only change single field.
推荐答案
与实时数据库一样,Cloud Firestore使用数据同步来更新任何已连接设备上的数据.但是,它也旨在有效地进行简单的一次性获取查询.
Like Realtime Database, Cloud Firestore uses data synchronization to update data on any connected device. However, it's also designed to make simple, one-time fetch queries efficiently.
默认情况下对查询建立索引:查询性能与结果集的大小成正比,而不与数据集的大小成正比.
Queries are indexed by default: Query performance is proportional to the size of your result set, not your data set.
Cloud Firestore仅向您的设备发送文档的不同之处.
提示:添加查询以限制您的侦听操作返回的数据,并使用仅将更新下载到数据的侦听器.
Tips:Add queries to limit the data that your listen operations return and use listeners that only download updates to data.
将侦听器放置在尽可能远的位置,以限制它们同步的数据量.您的听众应该接近您希望他们获得的数据.不要监听数据库根目录,因为这会导致整个数据库的下载.希望对您有帮助!
Place your listeners as far down the path as you can to limit the amount of data they sync. Your listeners should be close to the data you want them to get. Don't listen at the database root, as that results in downloads of your entire database.Hope it helps!
这篇关于Firestore是否仅同步差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!