Does simply pulling all users from firebase database and putting them into an array efficient?

Viewed 78

I have a simple iOS app that part of the app grabs all the users from firebase database so you can search them, and do different functions. Now my question is, if/when the app grows and there are thousands of users, does pulling all the users from the database and adding them to an array of [user]'s, still not crash or slow the app? I see so many people on youtube just loop through firebase and grab all the users. Please note I am excluding profile photos so there is no downloading images involved, just strings. I have some code I thought could solve this possible problem, but I am starting to wonder if there even is a problem with just fetching all the users from firebase and putting them into and array and then displayed in a tableview.

Here is some of my code right now, but it still I notice when I type in one letter, then turn airplane mode on, it downloaded all the users. I really need some help or some advice on this one, thanks.

   var checklers = [String]()
func updateSearchResults(for searchController: UISearchController) {
    if searchController.searchBar.text == "" {
        filteredUsers = users
    }
    else {
       print("refreshing")
        if let uidi = FIRAuth.auth()?.currentUser?.uid {
            view.addSubview(activityInd)
            activityInd.startAnimating()
       filteredUsers.removeAll()
        checklers.removeAll()
        let ref = FIRDatabase.database().reference()
        ref.child("users").queryOrderedByKey().observe(.value, with: { snapshot in
            if let userr = snapshot.value as? [String : AnyObject] {
                for (_, velt) in userr {
                    if let usernamerr = velt["Username"] as? String {
                    if usernamerr.lowercased().contains(searchController.searchBar.text!.lowercased()) {
                            let userNew = usera()
                            if let name = velt["Full Name"] as? String,  let uidd = velt["uid"] as? String {
                                userNew.name = name
                                userNew.username = usernamerr
                                userNew.uid = uidd
                                if self.checklers.contains(uidd) {
                                    print("already")
                                }
                                else {
                                    if userNew.uid != uidi {
                                self.filteredUsers.append(userNew)
                                        self.activityInd.stopAnimating()
                                        self.checklers.append(uidd)
                                    }

                                    print("added a user")
                                }
                            }
                        }
                    }
                    self.tableViewSearchUser.reloadData()
                }
            }

        })
        ref.removeAllObservers()
        }
//            filteredUsers = users.filter( { ($0.username?.lowercased().contains(searchController.searchBar.text!.lowercased()))! })
    }
    tableViewSearchUser.reloadData()
}

Please add any advice, thanks.

1 Answers
Related