|
|
|
@ -132,52 +132,34 @@ void runAsyncRegistrationsForStorage(OWSStorage *storage)
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(completion);
|
|
|
|
|
|
|
|
|
|
[((OWSDatabase *)self.database)collectRegistrationConnections];
|
|
|
|
|
|
|
|
|
|
runAsyncRegistrationsForStorage(self);
|
|
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ async registrations enqueued.", self.logTag);
|
|
|
|
|
|
|
|
|
|
// Flush the write queue to ensure all async registrations have begun.
|
|
|
|
|
[[self registrationConnection]
|
|
|
|
|
[[self newDatabaseConnection]
|
|
|
|
|
flushTransactionsWithCompletionQueue:dispatch_get_main_queue()
|
|
|
|
|
completionBlock:^{
|
|
|
|
|
// Block until all async registrations are complete.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: This has to happen on the "registration connections" for this
|
|
|
|
|
// database.
|
|
|
|
|
NSMutableSet<YapDatabaseConnection *> *pendingRegistrationConnectionSet = [
|
|
|
|
|
[((OWSDatabase *)self.database)clearCollectedRegistrationConnections] mutableCopy];
|
|
|
|
|
DDLogVerbose(@"%@ flushing registration connections: %zd.",
|
|
|
|
|
self.logTag,
|
|
|
|
|
pendingRegistrationConnectionSet.count);
|
|
|
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
for (YapDatabaseConnection *dbConnection in pendingRegistrationConnectionSet) {
|
|
|
|
|
[dbConnection
|
|
|
|
|
flushTransactionsWithCompletionQueue:dispatch_get_main_queue()
|
|
|
|
|
completionBlock:^{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
OWSAssert(!self.areAsyncRegistrationsComplete);
|
|
|
|
|
|
|
|
|
|
[pendingRegistrationConnectionSet
|
|
|
|
|
removeObject:dbConnection];
|
|
|
|
|
if (pendingRegistrationConnectionSet.count > 0) {
|
|
|
|
|
DDLogVerbose(@"%@ registration "
|
|
|
|
|
@"connection flushed.",
|
|
|
|
|
self.logTag);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ async registrations complete.",
|
|
|
|
|
self.logTag);
|
|
|
|
|
|
|
|
|
|
self.areAsyncRegistrationsComplete = YES;
|
|
|
|
|
|
|
|
|
|
completion();
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
OWSAssert(!self.areAsyncRegistrationsComplete);
|
|
|
|
|
|
|
|
|
|
[pendingRegistrationConnectionSet removeObject:dbConnection];
|
|
|
|
|
if (pendingRegistrationConnectionSet.count > 0) {
|
|
|
|
|
DDLogVerbose(@"%@ registration "
|
|
|
|
|
@"connection flushed.",
|
|
|
|
|
self.logTag);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DDLogVerbose(@"%@ async registrations complete.", self.logTag);
|
|
|
|
|
|
|
|
|
|
self.areAsyncRegistrationsComplete = YES;
|
|
|
|
|
|
|
|
|
|
completion();
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|