0

I have a firebase database of users, they have a field called active which can be true or false.

Can firebase make parallel data accesses? i.e. Would it be faster to retrieve the data in two separate queries, or a single?

e.g.

// Load all active users
Constants.firebase.usersRef.queryOrdered(byChild: "isActive").queryEqual(toValue: true).observeSingleEvent(of: .value, with: {
    (snapshot) in
    self.loadActiveUsers(snapshot: snapshot)
})

// Load all inactive users
Constants.firebase.usersRef.queryOrdered(byChild: "isActive").queryEqual(toValue: false).observeSingleEvent(of: .value, with: {
    (snapshot) in
    self.loadInactiveUsers(snapshot: snapshot)
})

Versus

// Load all users
Constants.firebase.usersRef.observeSingleEvent(of: .value, with: {
    (snapshot) in
    self.loadUsers(snapshot: snapshot)
})

Where loadActiveUsers & loadInactiveUsers simply create two arrays, one for the active and one for the inactive users. And loadUsers would do the same (by splitting across the active field).

KENdi
  • 7,576
  • 2
  • 16
  • 31
Vasseurth
  • 6,354
  • 12
  • 53
  • 81

1 Answers1

1

All interaction between a Firebase Database client and its back-end goes over a single socket connection. There is no benefit for parallelizing the requests.

Also see this longer explanation of how the requests are sent: 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
  • 565,676
  • 79
  • 828
  • 807