Merge branch 'charlesmchen/contactParsingPerf'

pull/1/head
Matthew Chen 8 years ago
commit c7d25a66ad

@ -88,8 +88,14 @@ class SystemContactsFetcher: NSObject {
} }
private func updateContacts() { private func updateContacts() {
AssertIsOnMainThread()
systemContactsHaveBeenRequestedAtLeastOnce = true systemContactsHaveBeenRequestedAtLeastOnce = true
let contactStore = self.contactStore
let allowedContactKeys = self.allowedContactKeys
DispatchQueue.global().async {
var systemContacts = [CNContact]() var systemContacts = [CNContact]()
do { do {
let contactFetchRequest = CNContactFetchRequest(keysToFetch: allowedContactKeys) let contactFetchRequest = CNContactFetchRequest(keysToFetch: allowedContactKeys)
@ -102,8 +108,11 @@ class SystemContactsFetcher: NSObject {
} }
let contacts = systemContacts.map { Contact(systemContact: $0) } let contacts = systemContacts.map { Contact(systemContact: $0) }
DispatchQueue.main.async {
self.delegate?.systemContactsFetcher(self, updatedContacts: contacts) self.delegate?.systemContactsFetcher(self, updatedContacts: contacts)
} }
}
}
private func startObservingContactChanges() { private func startObservingContactChanges() {
NotificationCenter.default.addObserver(self, NotificationCenter.default.addObserver(self,

@ -19,6 +19,8 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
@interface OWSContactsSyncing () @interface OWSContactsSyncing ()
@property (nonatomic, readonly) dispatch_queue_t serialQueue;
@property (nonatomic, readonly) OWSContactsManager *contactsManager; @property (nonatomic, readonly) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) OWSMessageSender *messageSender; @property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic) BOOL isRequestInFlight; @property (nonatomic) BOOL isRequestInFlight;
@ -70,6 +72,12 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
{ {
AssertIsOnMainThread(); AssertIsOnMainThread();
if (!self.serialQueue) {
_serialQueue = dispatch_queue_create("org.whispersystems.contacts.syncing", DISPATCH_QUEUE_SERIAL);
}
dispatch_async(self.serialQueue, ^{
if (self.isRequestInFlight) { if (self.isRequestInFlight) {
// De-bounce. It's okay if we ignore some new changes; // De-bounce. It's okay if we ignore some new changes;
// `sendSyncContactsMessageIfPossible` is called fairly // `sendSyncContactsMessageIfPossible` is called fairly
@ -103,17 +111,18 @@ NSString *const kTSStorageManagerOWSContactsSyncingLastMessageKey =
forKey:kTSStorageManagerOWSContactsSyncingLastMessageKey forKey:kTSStorageManagerOWSContactsSyncingLastMessageKey
inCollection:kTSStorageManagerOWSContactsSyncingCollection]; inCollection:kTSStorageManagerOWSContactsSyncingCollection];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(self.serialQueue, ^{
self.isRequestInFlight = NO; self.isRequestInFlight = NO;
}); });
} }
failure:^(NSError *error) { failure:^(NSError *error) {
DDLogError(@"%@ Failed to send contacts sync message with error: %@", self.tag, error); DDLogError(@"%@ Failed to send contacts sync message with error: %@", self.tag, error);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(self.serialQueue, ^{
self.isRequestInFlight = NO; self.isRequestInFlight = NO;
}); });
}]; }];
});
} }
- (void)sendSyncContactsMessageIfPossible - (void)sendSyncContactsMessageIfPossible

Loading…
Cancel
Save