-1

I am developing a mobile APP which has phone number authentication, once user logged in the APP, I will retrieve all the contacts on the user's phone addressbook to check who is using my APP, to do that I will loop through all the phone numbers and query firebase one by one, is there any better way to do this?.

My question similar to

how to compare my contact with the contacts uploaded in firebase database

How do I display list of only registered contacts(on firebase) from a client's address book(via phone numbers)

Querying Firebase Users to Check If Contact Exists in Database

None of them have a proper solution.

1) I have "invite" button in the app, when a new user installed my app, if the new user's phone number is present in the existing user's contact list, existing user's contact list should be updated without looping through all the contacts again. (I don't want to loop through all the contacts again and again whenever user clicks the contacts tab).

2) My database has location child in the user profile collection, whenever a user updates his location in the database, that new location to be reflected in the other user's phone who has his contact saved.

Please help me to solve these problems using Firebase.

leela
  • 1
  • 2
  • I don't know your platform but if it was me, I would load all of the phone numbers from Firebase into a Set, then load all of the phone numbers from the address book into a Set. Then find the intersection of of the two sets. In Swift it would be *firstSet.intersection(secondSet)* and the result set is the intersection. – Jay Dec 27 '17 at 18:57
  • Jay, my Firebase could have millions of phone numbers who are using currently my APP. I am using Ionic (typescript, Angularjs4) – leela Dec 28 '17 at 09:31
  • In that case, since there are far fewer phone numbers in the users address book, iterating through them with a query to find matches in Firebase is the way to go. – Jay Dec 28 '17 at 14:31
  • 1
    Questions 1) and 2) are independent to the original question and should be posted separately as the answers are different to the question posed. But... 1) A good use for a childAdded event so when a new user is added to the database and for each users app, if that users phone number exists, the contact should be updated to indicate this user is now using the app. 2) This sounds like a situation where a childChanged event would fire if the user changes their location which would notify clients and if that user exists, their location should be updated in the contact list. – Jay Dec 28 '17 at 14:33
  • Jay, thanks for your inputs will try these. – leela Dec 29 '17 at 06:55

1 Answers1

0

Neither Firebase Database nor Cloud Firestore has a built-in operator to compare two sets. You'll indeed will have to loop over each phone number and check if it's already present in the database.

This may not be nearly as slow as many developers think by the way, because the Firebase Realtime Database can likely pipeline the requests over its connection. See http://stackoverflow.com/q/35931526.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Frank, Thanks for your reply, I have updated my question could you please help me to solve those problems. – leela Dec 24 '17 at 18:53