Question

My iPhone application has to search for same phone numbers stored up on Parse. The flow is,

  • 1) Get contacts from user phone.
  • 2) See if each of those number exist on parse for other PFUser.
  • 3) Show Results by fetching PFUser with that number.

    This is same as whatsapp where we can see our contacts Using Whatsapp. So basically I know to make query and find out the users but my question is, is this Optimised way? For example if I have 50 contacts and each number will be obviously compared till match is found and if there are 1k/10K/More.. users then it will be very intensive work! So please help me find out great and fastest way for it, as I am beginner in using parse, any help appreciated. Thanks a lot experts.

No correct solution

OTHER TIPS

Have you read the Parse docs for PFQuery?

Assuming each PFUser has an attribute like phoneNumber, something like:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"phoneNumber in %@", phoneNumbersArray];
PFQuery *query = [PFQuery queryWithClassName:[PFUser parseClassName] predicate:predicate];
NSArray *pfUsers = [query findObjects];

There shouldn't be much more too it, unless you've changed something else, such as making PFUser rows not readable by others via ACL.

I am not quite clear if you are worried about the speed of the query or the size of the resultset, but I believe it is the query.

It is not like each of your phone numbers will be compared with every entry in your parse.com table. Parse makes handling your backend easy for you, by optimizing how queries are performed against your classes.

You can use a straightforward query constraint for your search. Put all the phone numbers you want to query for in an array, and then create a query like this:

PFQuery query = [PFUser query];
[query whereKey:@"phone" containedIn: arrayWithPhoneNumbers];

This will return a result set including all users with a phone number that matches any of the numbers in arrayWithPhoneNumbers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top