javascript - Child_added 订阅似乎下载了整个数据集

标签 javascript node.js firebase firebase-realtime-database

我有一个大型数据集(约 100k 条目),正在使用“child_added”事件订阅该数据集。使用 Node 7 和 firebase 3.6.1,执行此操作似乎会在触发单个 child_added 事件之前下载整个 100k 条目。

内存消耗在几十秒内显着增长,然后所有 child_added 事件都会快速触发。

这很慢:

require('firebase').
initializeApp({databaseURL: 'https://someproject.firebaseio.com'}).
database().ref('data').
on('child_added', (snap) => console.log(snap.key));

限制仍然很快(几秒钟的延迟):

require('firebase').
initializeApp({databaseURL: 'https://someproject.firebaseio.com'}).
database().ref('data').limitToFirst(10).
on('child_added', (snap) => console.log(snap.key));

鉴于 Firebase 的流式传输性质,我认为 child_added 订阅在完成任何操作之前将整个数据集下载到客户端并不是预期的行为。

我做错了什么,还是这是一个错误?

最佳答案

尽管在child_added部分中提取自firebase documentation它说:

The child_added event is typically used when retrieving a list of items from the database. Unlike value which returns the entire contents of the location, child_added is triggered once for each existing child and then again every time a new child is added to the specified path. The event callback is passed a snapshot containing the new child's data. For ordering purposes, it is also passed a second argument containing the key of the previous child.

At the first lines在该页面中,我们可以找到:

Data stored in a Firebase Realtime Database is retrieved by attaching an asynchronous listener to a database reference. The listener will be triggered once for the initial state of the data and again anytime the data changes.

似乎是其正常行为。它首先检索所有数据。

关于javascript - Child_added 订阅似乎下载了整个数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40768589/

相关文章:

firebase - Firebase 存储的权限问题,无法从管理面板下载文件

java - 无法通过 `CompileOptions.compilerArgs` 指定 -processorpath 或 --processor-path

javascript - Node : Dynamically create html from an object

javascript - $(this).hasClass ('e.g' ) 不返回

javascript - Firebase 数据库权限被拒绝错误

javascript - 使用 Jquery 加载文档时选择下拉选项

javascript - 如何改变FusionChart的背景颜色?

javascript - 如果日期相同,则按日期排序对象数组,然后按字符串值排序

javascript - Nodejs 中的 module.exports - fn 与 object

node.js - 如何先设置限制而不是创建 where 查询?