与addListenerForSingleValueEvent()一起使用时,Firebase返回旧的一组数据 [英] Firebase returning the old set of data when used with addListenerForSingleValueEvent()

查看:213
本文介绍了与addListenerForSingleValueEvent()一起使用时,Firebase返回旧的一组数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一次查询,不想保留一个监听器,以便在发送手动触发器时更新数据。

我的查询是这样的:

  var ref = this.instance.child('/ user / manish / today / events') 
.orderByChild('endDateTime')
.endAt(endEventTime)
.limitToLast(10)
.addListenerForSingleValueEvent(this.previousEventListeners);

$ b this.previousEventListeners = new com.google.firebase.database.ValueEventListener({
onDataChange:(snapshot)=> {
console.log(本地firebase访问权限值);
console.dump(this.testing(snapshot.getValue()));
let result = {
value:this.testing(snapshot.getValue )),
type:ValueChanged
};
console.dump(result);
},
onCancelled:(databaseError)=> {
console.log(databaseError.getMessage());
hideActivtiyIndi​​cator();
}
});

即使添加了与查询条件匹配的新记录,也会返回相同的数据集。



谢谢

解决方案

自己的应用。如果您需要启用磁盘持久性的最新数据,则需要订阅所有事件值更新,而不是仅调用一个值。这是特别令人困惑,因为尽管这种行为,Firebase仍然会调用服务器的一个新的价值 - 它只是不会返回给你!



我提交了支持请求与Firebase关于这一点,他们说这是预期的行为。我也建议他们澄清文件,他们说感谢这个全面的反馈。我们确实重视开发者的这种投入。这将包含在我们的功能请求列表中,并将与我们的工程师讨论。不幸的是,我不能分享任何时间表或明确的细节,因为这将在内部进行监测。



希望澄清情况。对于它的价值,我们用一个 FIRDatabaseReference 类别(iOS,对你的平台使用适当的隐喻)来解决这个问题,它增加了一个额外的功能。它调用 SingleValueEvent ,然后在500ms之后再次调用它,同时将值返回给调用者。 (如果呼叫者在此期间消失,则回调采用较弱的参考值)。500毫秒似乎是一个很好的选择 - 用户可以立即获得显示值,如果他们脱机或网络速度较慢,那么他们所看到的但是,如果他们在线,并有良好的网络访问,这给他们最新的数据很快。


I have a query to be made for once and don't want to keep a listener, so that the data updates when a manual trigger is sent.

So my query goes like this :

var ref = this.instance.child('/user/manish/today/events')
    .orderByChild('endDateTime')
    .endAt(endEventTime)
    .limitToLast(10)
    .addListenerForSingleValueEvent(this.previousEventListeners);


  this.previousEventListeners = new com.google.firebase.database.ValueEventListener({
      onDataChange: (snapshot) => {
        console.log("Value from native firebase access");
        console.dump(this.testing(snapshot.getValue()));
        let result = {
          value : this.testing(snapshot.getValue()),
          type : "ValueChanged"
        };
        console.dump(result);
      },
      onCancelled: (databaseError) => {
        console.log(databaseError.getMessage());
        hideActivtiyIndicator();
      }
  });

It Returns the same dataset even if a new record is added that matched the query criteria.

Thank you

解决方案

Yes, we experienced this behavior in our own apps. If you require up-to-date data with disk persistence enabled, you need to subscribe to all event value updates, not just call for a single value. It is particularly confusing because despite this behavior, Firebase will still call the server for a new value - it just won't return THAT one to you!

I filed a support request with Firebase about this and they said it was expected behavior. I also suggested they clarify the documentation and they said Thanks for this comprehensive feedback. We do value this kind of inputs from the developers. This will be included in our feature request list and will be discussed with our engineers. Unfortunately, I can't share any timeline or definite details as this will be monitored internally.

Hopefully that clarifies the situation. For what it's worth, we addressed this with a FIRDatabaseReference category (iOS, use appropriate metaphor for your platform) that adds an additional function. It calls SingleValueEvent and then calls it again 500ms later, returning the value both times to the caller. (The callback is taken with a weak reference in case the caller goes away in the meantime.) 500ms seems to be a good fit - the user is given an immediate value for display, and if they are offline or the network is slow, that's all they see. But if they're online and have decent network access, this gives them the latest data very shortly after.

这篇关于与addListenerForSingleValueEvent()一起使用时,Firebase返回旧的一组数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆