Checking for child causes poor scalability?

孤街浪徒 提交于 2019-12-25 11:51:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!