gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:13:04 24 4
gpt4 key购买 nike

我有一个大型数据集(约 10 万个条目),正在使用“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 订阅在任何事情完成之前将整个数据集下载到客户端并不是预期的行为。

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

最佳答案

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

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com