I am developing an iOS app using Swift 3 and Firebase. In this app I am creating a friend list with this structure:
Friends
User_id
Friend_user_id_1
Friend_user_id_2
I want to get a list of friends for a specific user and this is possible but since I only store ids of friends I am missing Name and Email.
My idea is to do a second query for each user in the friend list to get their personal data. The option to this is to store the Name and Email along the friend_id but that feels cumbersome since the friend might change their Name or Email.
Friends
User_id
Friend_user_id_1
Name
Email
Is it ok making a second query to get user details on each loop or is that a performance killer?
Do I have to save the Name and Email in list too?
Update
This is how I solve it right now
func setupContent() {
let user = FIRAuth.auth()?.currentUser
if user != nil {
DataService.dataService.FRIEND_REF.child((user?.uid)!).observe(.value, with: { snapshot in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
DataService.dataService.USER_REF.child(snap.key).observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as? Dictionary<String, AnyObject>
let friend = Friend(key: snap.key, dictionary: value!)
self.friends.insert(friend, at: 0)
self.tableView.reloadData()
}) { (error) in
print(error.localizedDescription)
}
}
}
})
}
}
Thankful for all help before I start coding.