How to separate initial data load from incremental children with Firebase?

后端 未结 4 1558
[愿得一人]
[愿得一人] 2020-11-30 03:09

I have an application where new children get added to Firebase every 5 seconds or so. I have thousands of children.

On application load, I\'d like to process the ini

4条回答
  •  没有蜡笔的小新
    2020-11-30 03:51

    Added a createdAt timestamp in the database and limited the child_added with the current time and it seems working fine to me.

    const onChildAdded = database()
      .ref(refURL)
      .limitToLast(constValues.LAST_MESSAGE_ADDED)
      .orderByChild('createdAt')
      .startAt(date.getTime())
      .on('child_added', (snapshot) => {
        parseMessage(snapshot);
      });
    
    database()
      .ref(refURL)
      .limitToLast(constValues.LAST_MESSAGES_LIMIT)
      .once('value', (snapshot) => {
        parseInitialMessages(snapshot);
        setLoading(false);
      });
    

提交回复
热议问题