简体   繁体   English

在Firebase上加载大量数据的最有效方法

[英]Most efficient way of loading large amount of data on Firebase

I have a simple viewpager with 2 fragments. 我有一个带有2个片段的简单viewpager。 One is for loading the newest posts and the other is loading top post, similar to the Reddit official app. 一个用于加载最新帖子,另一个用于加载热门帖子,类似于Reddit官方应用。

The way I currently load the Firebase data is to set obtain the snapshot through a singleValueListener and then sort after. 我当前加载Firebase数据的方式是设置通过singleValueListener获取快照,然后进行排序。 The "new" tab doesn't require any Queries since it is already placed in order, however, for "top" it would need to order by score. “新”标签不需要任何查询,因为它已经按顺序排列了,但是,对于“最高”标签,则需要按分数排序。 I then load those data directly into RecyclerView. 然后,我将这些数据直接加载到RecyclerView中。

Is there a more efficient way to loading the data? 有没有更有效的方式来加载数据? I currently have only a small database and it takes a while to load up, especially at the beginning. 我目前只有一个小型数据库,并且加载需要一段时间,尤其是在开始时。 The only idea I have right now is to use Firebase's limitTo methods, however, that would not work for the "top" posts tab as it'll need all the data to work with. 我现在唯一的想法是使用Firebase的limitTo方法,但这不适用于“顶部”帖子选项卡,因为它需要使用所有数据。

Thanks! 谢谢!

You did not post your code, so I can not comment on that. 您没有发布代码,因此我无法对此发表评论。 But from what you've described, the method you're using indeed is the most efficient one. 但是从您的描述来看,您使用的方法确实是最有效的方法。

From my own experience, I can vouch that Firebase is blazingly fast. 根据我自己的经验,我可以证明Firebase的速度非常快。 However, the delay you're experiencing right at the start is because Firebase needs to establish connection with the database in the beginning. 但是,您刚开始遇到的延迟是因为Firebase需要在开始时与数据库建立连接。 Once the connection is established, updates and downloads are in real time ( only constrained to the amount of data you're editing and your network quality ). 建立连接后,实时更新和下载(仅受您正在编辑的数据量和网络质量的限制)。 One thing that you can look into is enabling offline persistence, so that the users of your app are not shown a blank screen at app startup. 您可以研究的一件事是启用离线持久性,以便在应用程序启动时不会向您的应用程序用户显示空白屏幕。 You can read more about it here . 您可以在此处了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM