在Firebase中处理并行读取操作 [英] Dealing with parallel read operations at Firebase

查看:40
本文介绍了在Firebase中处理并行读取操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在Firebase(基于Java/Android)上处理多个并行读取操作"的最佳方法是注册一个SingleValueEventListener并处理onDataChanged事件中的数据.假设我有三个不同的DatabaseReference位置,并且立即注册了三个侦听器,

I wonder what is the best way to deal with multiple parallel 'read operations', that is registering a SingleValueEventListener and handling data in onDataChanged event, at Firebase (Java-based/Android). Let´s say, I have three different DatabaseReference locations and three listeners are registered right away,

  1. 是否有可能将整个东西捆绑在一起,以便只有一个请求?
  2. 实现等待"的最佳方法是什么,以便在三个DataChange事件中的最后一个传递数据时立即执行代码,而不嵌套它们,以便在以下情况下仅注册以下事件:上一个?

推荐答案

  1. 没有办法(也不需要)将读取的内容合并为一个请求.Firebase数据库客户端通过单个连接流水线处理请求.参见

  1. There is no way (nor a need) to combine the reads into a single request. The Firebase database client pipelines the requests over a single connection. See my answer here for how this works and why this addresses the concerns about round trip performance that most developers have.

在由 Promise.all()处理的JavaScript代码中.在Android中,您可以使用 Task s完成相同的任务.道格·史蒂文森(Doug Stevenson)为此撰写了一系列博客文章,建议阅读以获取详细信息:第2部分

In JavaScript code that is handled by Promise.all(). In Android you can use Tasks to accomplish the same. Doug Stevenson wrote a great series of blog post on this, which I recommend reading for details: part 1, part 2, part 3 (which covers chaining tasks using a Continuation), part 4 (which finally covers running tasks in parallel using Tasks.whenAll(...)).

这篇关于在Firebase中处理并行读取操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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