From a264268253327012b1008f4f5c92e9796a212789 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 18 Apr 2018 16:28:15 -0400 Subject: [PATCH] Rework flush of registration connection(s). --- .../src/Storage/OWSPrimaryStorage.m | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/SignalServiceKit/src/Storage/OWSPrimaryStorage.m b/SignalServiceKit/src/Storage/OWSPrimaryStorage.m index 5a2701434..9a182e0b6 100644 --- a/SignalServiceKit/src/Storage/OWSPrimaryStorage.m +++ b/SignalServiceKit/src/Storage/OWSPrimaryStorage.m @@ -136,31 +136,23 @@ void runAsyncRegistrationsForStorage(OWSStorage *storage) DDLogVerbose(@"%@ async registrations enqueued.", self.logTag); - // Flush the write queue to ensure all async registrations have begun. - [[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. - - 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(); - }]; + // Use an empty read/write transaction to to ensure all async registrations have completed. + [[self newDatabaseConnection] asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + // Do nothing. + // + // We can't use flushTransactionsWithCompletionQueue because it + // doesn't flush the YapDatabase.writeQueue. + } + completionQueue:dispatch_get_main_queue() + completionBlock:^{ + OWSAssert(!self.areAsyncRegistrationsComplete); + + DDLogVerbose(@"%@ async registrations complete.", self.logTag); + + self.areAsyncRegistrationsComplete = YES; + + completion(); + }]; } + (void)protectFiles