Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我们有大量孩子时, spanshot.numChildren()的性能如何?
firebase 是否会通过其所有孩子来计算孩子的数量,还是在添加新孩子时维护一个计数器?
DataSnapshot 包含内存中本地的所有数据。在 DataSnapshot 上调用 numChildren 或其他任何内容都不会导致任何网络 I/O。
请注意,这意味着您在生成这些快照时应该小心——如果您只想计算某物的数量,则加载大型 DataSnapshot 然后调用 numChildren() 比维护单独的计数要昂贵得多孩子的数量,并在每次添加新孩子时使用事务更新它。