Reputation: 8351
I have created one application the same as WhatsApp
to chat with the same industry people and my basic concept is to sync user contact and find a user who is using this app and users can chat with each other.
Contact sync I have done in my application and its working fine till 100 to 500 contacts but if any user has 2000 to 3000 contacts in his contact book its taking time to sync with the server.
I am using the below code to get user contacts and sent them to the server.
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
NSMutableArray *contacListAddIntoDatabase = [NSMutableArray new];
for (id record in allContacts) {
ABRecordRef thisContact = (__bridge ABRecordRef)record;
//save Contact in DataBase.
}
After saving all records in the local database
i am sending that record to the server to check if that contact is a user of my app and get backlist of users who are using my app. I have implemented paging in contactsync service
.
Here is my contact sync to server code :
if ([[APP_DELEGATE contactArrayForSync] count] > 0) {
int long pageSize = ([[APP_DELEGATE contactArrayForSync] count] > CONTACT_SYNC_PAGE_SIZE ) ? CONTACT_SYNC_PAGE_SIZE : [[APP_DELEGATE contactArrayForSync] count];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:contactList
options:0
error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[[APP_DELEGATE apiManager] syncUserContacts:[APP_DELEGATE getEncryptedUserID] andJSONString:jsonString withCallback:^(BOOL success, id responseObject) {
//Update DataBase as per server response
}];
}
to sync 2000 contacts it's taking around 2min to sync and its very large amount of time to sync contacts.
I want to reduce this time so is there any way to get sync data in sorter time.
I am stuck here and the client asking a faster solution to sync my contacts.
Note: In the server, I have around 50000 records in my Contact table and it may increase in the future.
any suggestions will be appreciated.
UPDATE: At the first time I am sending all contacts to a server in paging that's fine but after first sync every second sync I need to send only updated or newly added records right now I am sending all record to the server every time.
so how can I get an updated record or newly added record and faster next time sync also?
Upvotes: 3
Views: 2209
Reputation: 11
You can use realm for local storage with observe function. Then you can listen changes from realm for remote sync.
Upvotes: 0
Reputation: 2310
I think you can speed up the syncing by changing some implementation to your code as well on server side code. you send all phone numbers in on array of dictionary (name, all phone number comma separated) you need to create this structure while you are fetching the records from address book, now change your logic accordingly on the server side. both of your task storing in database and syncing can be done on different threads.
Hope this helps for you.
Upvotes: 1