简体   繁体   中英

Most efficient way of loading large amount of data on Firebase

I have a simple viewpager with 2 fragments. One is for loading the newest posts and the other is loading top post, similar to the Reddit official app.

The way I currently load the Firebase data is to set obtain the snapshot through a singleValueListener and then sort after. 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.

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.

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. However, the delay you're experiencing right at the start is because Firebase needs to establish connection with the database in the beginning. 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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