Firebase:侦听多个用户节点 [英] Firebase: Listening to multiple user nodes

查看:79
本文介绍了Firebase:侦听多个用户节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase和Geofire开发应用程序.假设在当前位置运行地理查询时,假设我在OnKeyEntered覆盖方法中收到10个键.这些键中的每个键实际上都是Firebase中的一个用户节点.我需要听取查询区域中的每个用户的任何数据更改,以便可以在地图上实时显示更新.

I'm working on an app using Firebase and Geofire. On running the Geo query at the current location, let's say I receive 10 keys in the OnKeyEntered override method. Each of these keys is essentially a user node in Firebase. I need to listen to each of the user in the query area for any data change so that I can show updates on the map in realtime.

当前,我为每个输入的键添加一个ValueEventListener,但是我不确定同时启动这么多的侦听器是否是个好主意.查询区域中的用户可能超过50.这意味着我可以有50个开放的侦听器!

Currently, I'm adding a ValueEventListener for every key entered but I'm not sure if starting so many listeners at the same time is good idea. The users in the query area can potentially be more than 50. That means I could have 50 open listeners!

有更好的方法吗?我试图找出一个只针对地理位置查询键进行过滤的firebase查询,但未成功.

Is there a better way to go about it? I was trying to figure out a firebase query to filter on only the geo query keys but was unsuccessful.

任何帮助都会很棒!

推荐答案

侦听器在计算上并不昂贵,除非您的侦听器由于要侦听的数据经常更改而将被非常频繁地触发.

Listeners are not computationally expensive, unless you have one that's going to be triggered very frequently because the data it's listening to is changing often.

在您实际发现需要优化代码之前,请不要陷入优化代码的陷阱.当您发现性能很差时,就该进行优化了.如果您需要一群听众来完成您的工作,请继续进行.只要知道您的实际上限是多少,并确保对问题进行上限测试即可.

Don't fall into the trap of optimizing your code before you actually observe a need to optimize it. When you see that performance is poor, that's the time to make optimizations. If you need a bunch of listeners to get your work done, go ahead and do that. Just know what your practical upper bound it, and be sure to test that upper bound for problems.

这篇关于Firebase:侦听多个用户节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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