Move more work off the main thread.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 9573e0e16d
commit facbc56062

@ -178,9 +178,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
object:nil]; object:nil];
// Try to start processing. // Try to start processing.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [self scheduleProcessing];
[self scheduleProcessing];
});
return self; return self;
} }
@ -198,30 +196,33 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
// Schedules a processing pass, unless one is already scheduled. // Schedules a processing pass, unless one is already scheduled.
- (void)scheduleProcessing - (void)scheduleProcessing
{ {
@synchronized(self) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
{ @synchronized(self)
if ([TSDatabaseView hasPendingViewRegistrations]) { {
DDLogInfo(@"%@ Deferring read receipt processing due to pending database view registrations.", self.tag); if ([TSDatabaseView hasPendingViewRegistrations]) {
return; DDLogInfo(
} @"%@ Deferring read receipt processing due to pending database view registrations.", self.tag);
if (self.isProcessing) { return;
return; }
} if (self.isProcessing) {
return;
}
self.isProcessing = YES; self.isProcessing = YES;
// Process read receipts every N seconds. // Process read receipts every N seconds.
// //
// We want a value high enough to allow us to effectively de-duplicate, // We want a value high enough to allow us to effectively de-duplicate,
// read receipts without being so high that we risk not sending read // read receipts without being so high that we risk not sending read
// receipts due to app exit. // receipts due to app exit.
const CGFloat kProcessingFrequencySeconds = 3.f; const CGFloat kProcessingFrequencySeconds = 3.f;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kProcessingFrequencySeconds * NSEC_PER_SEC)), dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kProcessingFrequencySeconds * NSEC_PER_SEC)),
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{ ^{
[self process]; [self process];
}); });
} }
});
} }
- (void)process - (void)process

Loading…
Cancel
Save