0

The Structure of data is

Users_Node
{


 UserID1
    {
    firstName:...
    lastName:...
    ...
    }
    UserID2
    {
    firstName:...
    lastName:...
    ...
    }
    UserID3
    {
    firstName:...
    lastName:...
    ...
    }
    UserID4
    {
    firstName:...
    lastName:...
    ...
    }
    UserID5
    {
    firstName:...
    lastName:...
    ...
    }
.
.
.
.
.
.
    UserID10000
    {
    firstName:...
    lastName:...
    ...
    }

}


User_Chat_Node
{
.....
}

Other_Nodes....
{
}

How to get the details of only some pre-known IDs lets say UserID4 ,UserID5,UserID2000,UserID2005.

Option 1)

mRef.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                CurrentUserDetails = dataSnapshot.getValue(UserDetails.class);
//Add the item to my Array
                            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

Problem - Listner will be created 10000 times.

Option 2)

Parent_mRef.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                //if(RequiredID == dataSnapshot.getValue(UserDetails.class).getUserID() )
        //Add the item to my Array 
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {

            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {

            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

Problem - Will have to loop 10000 times.

Isn't There a simpler way like

//For each item in MyListofUserIDs
{
    MyArray [location]    = Parent_ref.child(MyListofUserIDs[location]).getValue(UserDetails.class)

}
user3450804
  • 83
  • 1
  • 6
  • are these user ids from some continuous range like [UserID4, UserID5, UserID6, UserID7] or just any set of ids? – pkacprzak Apr 06 '16 at 00:35
  • @pkacprzak Just some random IDs. – user3450804 Apr 06 '16 at 01:01
  • No there isn't, unless (as @pkacprzak says) the ids are in a range. But loading the items like this is *a lot* faster than you'd imagine. See [my answer here](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 Apr 06 '16 at 03:42

0 Answers0