问题
This isn't a question that nessacarily has a 'solution', but I was wondering if this code would cause memory issues when scaled much larger.
ref.child("Teams").observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.hasChild(self.teamName.text!){
//Sets the a single team's values
} else {
//Displays a missing team alert
let alert = UIAlertController(title: "Error" , message: "Team does not exist", preferredStyle: .alert)
let actio1n = UIAlertAction(title: "Ok" , style: .cancel , handler: nil)
alert.addAction(actio1n)
self.present(alert, animated: true, completion: nil)
}
})
I'm sort of wondering if Firebase would just load the surface level (each individual team's ID), or if it would load more in-depth. What are your thoughts?
回答1:
Firebase will fetch the FULL tree under Teams. More details here:
[...] when you fetch data at a location in your database, you also retrieve all of its child nodes [...]
回答2:
As Mihai said: observing a node will retrieve that entire node.
To check if a specific child node exists, observe only that child node:
ref.child("Teams").child(self.teamName.text!).observeSingleEvent(of: .value, with: { (snapshot) in
if snapshot.exists(){
...
}
})
来源:https://stackoverflow.com/questions/43213048/checking-for-child-causes-poor-scalability