2

I have a list" of data which contains its members. And members are having the list of user ids in the following format:

"list" : {
    "-pushid1" : {
         "members" : {
             "uid1" : true,
             "uid2" : true
         }
    },
    "-pushid2" : {
         "members" : {
             "uid2" : true,
             "uid3" : true
         }
    },
    .....
}

I am trying to retrieve the list of user1 with the following query:

FirebaseDatabase.getInstance().getReference().child("list").orderByChild("members/" + FirebaseAuth.getInstance().getCurrentUser().getUid()).equalTo(true);

For querying the list of 1000+ records, it is taking 5+ seconds. How can I define the index at which level to improve the retrieval speed?

RBK
  • 2,481
  • 2
  • 30
  • 52
  • I just answered a *very* similar question here: http://stackoverflow.com/questions/42952914/firebase-database-select-by-inner-field/42953941#42953941. The solution I proposed there is what you should also do here: create a structure that holds the "push ids for each member". With that you can do a direct (=fast) lookup, instead of needing a nested query. – Frank van Puffelen Mar 22 '17 at 14:26
  • 1
    @FrankvanPuffelen Out of curiosity​, for that list to show, i need to query for each and every item again and again. If in a firebase adapter, querying data in a populateViewHolder slows down the performance in my experience.. This structure however looks good to me. – kirtan403 Mar 22 '17 at 17:59
  • Please quantify "slows down", as it should not be much. See http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen Mar 22 '17 at 19:27
  • @FrankvanPuffelen Yes, I know this works better, but when you use recycler view and the caching is turned off in android, it will take up a lot of bandwidth, isn't it? – kirtan403 Mar 23 '17 at 05:06
  • Because it will make a request everytime a view is scrolled in and brought to screen. The no of request and response is pretty fast no doubt about it, but it makes unnecessary requests while scrolling. – kirtan403 Mar 23 '17 at 05:08

0 Answers0