From 4455185f8414d5cc916b70d7eac85a667265870f Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Aug 2019 11:31:16 -0300 Subject: [PATCH 1/7] Remove YDB & primary storage usage. --- .../MessageDetailViewController.swift | 7 ++-- Signal/src/util/Backup/OWSBackup.m | 34 ++++++++----------- Signal/test/Models/MantlePerfTest.swift | 4 --- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index ed7cd344d3..135341ed5d 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -33,8 +33,6 @@ class MessageDetailViewController: OWSViewController { // MARK: Properties - let uiDatabaseConnection: YapDatabaseConnection - var bubbleView: UIView? let mode: MessageMetadataViewMode @@ -85,7 +83,6 @@ class MessageDetailViewController: OWSViewController { self.viewItem = viewItem self.message = message self.mode = mode - self.uiDatabaseConnection = OWSPrimaryStorage.shared().uiDatabaseConnection self.conversationStyle = ConversationStyle(thread: thread) super.init(nibName: nil, bundle: nil) @@ -204,8 +201,8 @@ class MessageDetailViewController: OWSViewController { lazy var thread: TSThread = { var thread: TSThread? - self.uiDatabaseConnection.read { transaction in - thread = self.message.thread(transaction: transaction.asAnyRead) + databaseStorage.uiRead { transaction in + thread = self.message.thread(transaction: transaction) } return thread! }() diff --git a/Signal/src/util/Backup/OWSBackup.m b/Signal/src/util/Backup/OWSBackup.m index fe0a2bc3a4..044900ca1e 100644 --- a/Signal/src/util/Backup/OWSBackup.m +++ b/Signal/src/util/Backup/OWSBackup.m @@ -78,8 +78,6 @@ NSError *OWSBackupErrorWithDescription(NSString *description) // TODO: Observe Reachability. @interface OWSBackup () -@property (nonatomic, readonly) YapDatabaseConnection *dbConnection; - // This property should only be accessed on the main thread. @property (nonatomic, nullable) OWSBackupExportJob *backupExportJob; @@ -101,8 +99,6 @@ NSError *OWSBackupErrorWithDescription(NSString *description) @implementation OWSBackup -@synthesize dbConnection = _dbConnection; - - (SDSDatabaseStorage *)databaseStorage { return SDSDatabaseStorage.shared; @@ -113,7 +109,7 @@ NSError *OWSBackupErrorWithDescription(NSString *description) static SDSKeyValueStore *keyValueStore = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - keyValueStore = [[SDSKeyValueStore alloc] initWithCollection:@"OWSPrimaryStorage_OWSBackupCollection"]; + keyValueStore = [[SDSKeyValueStore alloc] initWithCollection:@"OWSBackupCollection"]; }); return keyValueStore; } @@ -183,16 +179,6 @@ NSError *OWSBackupErrorWithDescription(NSString *description) }); } -- (YapDatabaseConnection *)dbConnection -{ - @synchronized(self) { - if (!_dbConnection) { - _dbConnection = self.primaryStorage.newDatabaseConnection; - } - return _dbConnection; - } -} - #pragma mark - Dependencies - (OWSPrimaryStorage *)primaryStorage @@ -746,8 +732,12 @@ NSError *OWSBackupErrorWithDescription(NSString *description) - (NSArray *)attachmentRecordNamesForLazyRestore { NSMutableArray *recordNames = [NSMutableArray new]; - [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - id ext = [transaction ext:TSLazyRestoreAttachmentsDatabaseViewExtensionName]; + [self.databaseStorage readWithBlock:^(SDSAnyReadTransaction *transaction) { + // GRDB TODO: + if (transaction.transitional_yapReadTransaction == nil) { + return; + } + id ext = [transaction.transitional_yapReadTransaction ext:TSLazyRestoreAttachmentsDatabaseViewExtensionName]; if (!ext) { OWSFailDebug(@"Could not load database view."); return; @@ -764,7 +754,7 @@ NSError *OWSBackupErrorWithDescription(NSString *description) TSAttachmentPointer *attachmentPointer = object; OWSBackupFragment *_Nullable lazyRestoreFragment = - [attachmentPointer lazyRestoreFragmentWithTransaction:transaction.asAnyRead]; + [attachmentPointer lazyRestoreFragmentWithTransaction:transaction]; if (lazyRestoreFragment == nil) { OWSFailDebug( @"Invalid object: %@ in collection:%@", [object class], collection); @@ -779,8 +769,12 @@ NSError *OWSBackupErrorWithDescription(NSString *description) - (NSArray *)attachmentIdsForLazyRestore { NSMutableArray *attachmentIds = [NSMutableArray new]; - [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - id ext = [transaction ext:TSLazyRestoreAttachmentsDatabaseViewExtensionName]; + [self.databaseStorage readWithBlock:^(SDSAnyReadTransaction *transaction) { + // GRDB TODO: + if (transaction.transitional_yapReadTransaction == nil) { + return; + } + id ext = [transaction.transitional_yapReadTransaction ext:TSLazyRestoreAttachmentsDatabaseViewExtensionName]; if (!ext) { OWSFailDebug(@"Could not load database view."); return; diff --git a/Signal/test/Models/MantlePerfTest.swift b/Signal/test/Models/MantlePerfTest.swift index 5043dc5848..67b9053755 100644 --- a/Signal/test/Models/MantlePerfTest.swift +++ b/Signal/test/Models/MantlePerfTest.swift @@ -8,10 +8,6 @@ import XCTest class MantlePerfTest: SignalBaseTest { - var primaryStorage: OWSPrimaryStorage { - return SSKEnvironment.shared.primaryStorage - } - override func setUp() { // Put setup code here. This method is called before the invocation of each test method in the class. } From c9b162d1e2df13056be21e2245e6919a3f74642b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Aug 2019 11:37:21 -0300 Subject: [PATCH 2/7] Remove YDB & primary storage usage. --- Signal/src/AppDelegate.m | 4 +++- Signal/src/ViewControllers/LongTextViewController.swift | 8 ++------ Signal/src/util/Backup/OWSBackup.m | 7 ------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 14a4d1f04f..957d93cbb2 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -212,7 +212,7 @@ static NSTimeInterval launchStartedAt; OWSLogWarn(@"application: didFinishLaunchingWithOptions."); [Cryptography seedRandom]; - // XXX - careful when moving this. It must happen before we initialize OWSPrimaryStorage. + // XXX - careful when moving this. It must happen before we load YDB and/or GRDB. [self verifyDBKeysAvailableBeforeBackgroundLaunch]; // We need to do this _after_ we set up logging, when the keychain is unlocked, @@ -324,6 +324,8 @@ static NSTimeInterval launchStartedAt; return; } + // GRDB TODO: We should consult YDB and GRDB. This should be done via storage coordinator, + // which knows which checks we need to do. if (![OWSPrimaryStorage isDatabasePasswordAccessible]) { OWSLogInfo(@"exiting because we are in the background and the database password is not accessible."); diff --git a/Signal/src/ViewControllers/LongTextViewController.swift b/Signal/src/ViewControllers/LongTextViewController.swift index d9f8ad1cb4..a2804fff17 100644 --- a/Signal/src/ViewControllers/LongTextViewController.swift +++ b/Signal/src/ViewControllers/LongTextViewController.swift @@ -21,10 +21,6 @@ public class LongTextViewController: OWSViewController { return SDSDatabaseStorage.shared } - var uiDatabaseConnection: YapDatabaseConnection { - return OWSPrimaryStorage.shared().uiDatabaseConnection - } - // MARK: - Properties @objc @@ -78,8 +74,8 @@ public class LongTextViewController: OWSViewController { let uniqueId = self.viewItem.interaction.uniqueId do { - try uiDatabaseConnection.read { transaction in - guard TSInteraction.anyFetch(uniqueId: uniqueId, transaction: transaction.asAnyRead) != nil else { + try databaseStorage.uiReadThrows { transaction in + guard TSInteraction.anyFetch(uniqueId: uniqueId, transaction: transaction) != nil else { Logger.error("Message was deleted") throw LongTextViewError.messageWasDeleted } diff --git a/Signal/src/util/Backup/OWSBackup.m b/Signal/src/util/Backup/OWSBackup.m index 044900ca1e..2fe4386183 100644 --- a/Signal/src/util/Backup/OWSBackup.m +++ b/Signal/src/util/Backup/OWSBackup.m @@ -181,13 +181,6 @@ NSError *OWSBackupErrorWithDescription(NSString *description) #pragma mark - Dependencies -- (OWSPrimaryStorage *)primaryStorage -{ - OWSAssertDebug(SSKEnvironment.shared.primaryStorage); - - return SSKEnvironment.shared.primaryStorage; -} - - (TSAccountManager *)tsAccountManager { OWSAssertDebug(SSKEnvironment.shared.tsAccountManager); From 2c616f4f3e7724af977bb7b3d02c749a687b7b09 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Aug 2019 11:41:09 -0300 Subject: [PATCH 3/7] Remove YDB & primary storage usage. --- .../SelectThreadViewController.m | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/SignalMessaging/ViewControllers/SelectThreadViewController.m b/SignalMessaging/ViewControllers/SelectThreadViewController.m index 4dd5d3091b..107003198b 100644 --- a/SignalMessaging/ViewControllers/SelectThreadViewController.m +++ b/SignalMessaging/ViewControllers/SelectThreadViewController.m @@ -19,10 +19,10 @@ #import #import #import +#import #import #import #import -#import NS_ASSUME_NONNULL_BEGIN @@ -30,12 +30,12 @@ NS_ASSUME_NONNULL_BEGIN ThreadViewHelperDelegate, ContactsViewHelperDelegate, UISearchBarDelegate, - NewNonContactConversationViewControllerDelegate> + NewNonContactConversationViewControllerDelegate, + SDSDatabaseStorageObserver> @property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper; @property (nonatomic, readonly) FullTextSearcher *fullTextSearcher; @property (nonatomic, readonly) ThreadViewHelper *threadViewHelper; -@property (nonatomic, readonly) YapDatabaseConnection *uiDatabaseConnection; @property (nonatomic, readonly) OWSTableViewController *tableViewController; @@ -72,19 +72,7 @@ NS_ASSUME_NONNULL_BEGIN _threadViewHelper = [ThreadViewHelper new]; _threadViewHelper.delegate = self; - _uiDatabaseConnection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection]; -#ifdef DEBUG - _uiDatabaseConnection.permittedTransactions = YDB_AnyReadTransaction; -#endif - [_uiDatabaseConnection beginLongLivedReadTransaction]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(yapDatabaseModified:) - name:YapDatabaseModifiedNotification - object:OWSPrimaryStorage.sharedManager.dbNotificationObject]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(yapDatabaseModifiedExternally:) - name:YapDatabaseModifiedExternallyNotification - object:nil]; + [self.databaseStorage addDatabaseStorageObserver:self]; [self createViews]; @@ -124,21 +112,29 @@ NS_ASSUME_NONNULL_BEGIN self.tableViewController.tableView.estimatedRowHeight = 60; } -- (void)yapDatabaseModifiedExternally:(NSNotification *)notification +#pragma mark - SDSDatabaseStorageObserver + +- (void)databaseStorageDidUpdateWithChange:(SDSDatabaseStorageChange *)change { OWSAssertIsOnMainThread(); + OWSAssertDebug(AppReadiness.isAppReady); - OWSLogVerbose(@""); - - [self.uiDatabaseConnection beginLongLivedReadTransaction]; [self updateTableContents]; } -- (void)yapDatabaseModified:(NSNotification *)notification +- (void)databaseStorageDidUpdateExternally { OWSAssertIsOnMainThread(); - - [self.uiDatabaseConnection beginLongLivedReadTransaction]; + OWSAssertDebug(AppReadiness.isAppReady); + + [self updateTableContents]; +} + +- (void)databaseStorageDidReset +{ + OWSAssertIsOnMainThread(); + OWSAssertDebug(AppReadiness.isAppReady); + [self updateTableContents]; } From 311edf1bd48b3b754c65940a3256d040d3803483 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Aug 2019 11:53:31 -0300 Subject: [PATCH 4/7] Remove YDB & primary storage usage. --- .../src/Account/TSAccountManager.m | 14 +--------- .../src/Messages/OWSIdentityManager.m | 9 +++--- .../src/Messages/OWSMessageManager.m | 1 - .../src/Network/OWSSignalService.m | 28 ++++++------------- 4 files changed, 14 insertions(+), 38 deletions(-) diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index 5d817c22df..8e0b67d865 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -250,8 +250,6 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa @synchronized (self) { __block NSString *_Nullable result; - // GRDB TODO: Until GRDB migration is complete, we need to load this from YDB, - // // * YAPDBJobRecordFinder uses a secondary index. // * Yaps views and indices enumerate all (per whitelist or blacklist) entities when building or updating the // index. Views and indices can be built or re-built on launch. @@ -261,20 +259,10 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa // * OWSOutgoingSyncMessage extends TSOutgoingMessage whose deserialization initializer initWithCoder uses // TSAccountManager.localNumber. // * TSAccountManager.localNumber is persisted in the database. - // * When we load TSAccountManager.localNumber we use the "current" database which might be GRDB. GRDB might not - // be populated because the migration hasn't occurred yet. - // - // GRDB TODO: GRDB_MIGRATION_COMPLETE might eventually be replaced by a flag set at runtime. -#ifdef GRDB_MIGRATION_COMPLETE + // * When we load TSAccountManager.localNumber we use the "current" database which might be GRDB. [self.databaseStorage readWithBlock:^(SDSAnyReadTransaction *transaction) { result = [self.keyValueStore getString:TSAccountManager_RegisteredNumberKey transaction:transaction]; }]; -#else - [self.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { - result = - [self.keyValueStore getString:TSAccountManager_RegisteredNumberKey transaction:transaction.asAnyRead]; - }]; -#endif return result; } } diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index f26590e997..e47402e8dd 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.m @@ -11,7 +11,6 @@ #import "OWSFileSystem.h" #import "OWSMessageSender.h" #import "OWSOutgoingNullMessage.h" -#import "OWSPrimaryStorage.h" #import "OWSRecipientIdentity.h" #import "OWSVerificationStateChangeMessage.h" #import "OWSVerificationStateSyncMessage.h" @@ -30,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN // Storing our own identity key -NSString *const OWSPrimaryStorageIdentityKeyStoreIdentityKey = @"TSStorageManagerIdentityKeyStoreIdentityKey"; +NSString *const kIdentityKeyStore_IdentityKey = @"TSStorageManagerIdentityKeyStoreIdentityKey"; // Don't trust an identity for sending to unless they've been around for at least this long const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; @@ -128,7 +127,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa { [self.databaseQueue writeWithBlock:^(SDSAnyWriteTransaction *transaction) { [self.ownIdentityKeyValueStore setObject:[Curve25519 generateKeyPair] - key:OWSPrimaryStorageIdentityKeyStoreIdentityKey + key:kIdentityKeyStore_IdentityKey transaction:transaction]; }]; } @@ -185,7 +184,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa { OWSAssertDebug(transaction); id _Nullable object = - [self.ownIdentityKeyValueStore getObject:OWSPrimaryStorageIdentityKeyStoreIdentityKey transaction:transaction]; + [self.ownIdentityKeyValueStore getObject:kIdentityKeyStore_IdentityKey transaction:transaction]; if ([object isKindOfClass:[ECKeyPair class]]) { return (ECKeyPair *)object; } else { @@ -951,7 +950,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa NSMutableArray *identityKeysToRemove = [NSMutableArray new]; for (NSString *key in [self.ownIdentityKeyValueStore allKeysWithTransaction:transaction]) { - if ([key isEqualToString:OWSPrimaryStorageIdentityKeyStoreIdentityKey]) { + if ([key isEqualToString:kIdentityKeyStore_IdentityKey]) { // Don't delete our own key. return; } diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 11cfc3b22f..212e21bedf 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -24,7 +24,6 @@ #import "OWSMessageSender.h" #import "OWSMessageUtils.h" #import "OWSOutgoingReceiptManager.h" -#import "OWSPrimaryStorage.h" #import "OWSReadReceiptManager.h" #import "OWSRecordTranscriptJob.h" #import "OWSSyncGroupsRequestMessage.h" diff --git a/SignalServiceKit/src/Network/OWSSignalService.m b/SignalServiceKit/src/Network/OWSSignalService.m index 23185da514..aa6924859d 100644 --- a/SignalServiceKit/src/Network/OWSSignalService.m +++ b/SignalServiceKit/src/Network/OWSSignalService.m @@ -7,7 +7,6 @@ #import "OWSCensorshipConfiguration.h" #import "OWSError.h" #import "OWSHTTPSecurityPolicy.h" -#import "OWSPrimaryStorage.h" #import "TSAccountManager.h" #import "TSConstants.h" #import @@ -15,13 +14,11 @@ NS_ASSUME_NONNULL_BEGIN -NSString *const kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated +NSString *const kisCensorshipCircumventionManuallyActivatedKey = @"kTSStorageManager_isCensorshipCircumventionManuallyActivated"; -NSString *const kOWSPrimaryStorage_isCensorshipCircumventionManuallyDisabled +NSString *const kisCensorshipCircumventionManuallyDisabledKey = @"kTSStorageManager_isCensorshipCircumventionManuallyDisabled"; -NSString *const kOWSPrimaryStorage_ManualCensorshipCircumventionDomain - = @"kTSStorageManager_ManualCensorshipCircumventionDomain"; -NSString *const kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode +NSString *const kManualCensorshipCircumventionCountryCodeKey = @"kTSStorageManager_ManualCensorshipCircumventionCountryCode"; NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = @@ -120,7 +117,7 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = { __block BOOL result; [self.databaseStorage readWithBlock:^(SDSAnyReadTransaction *transaction) { - result = [self.keyValueStore getBool:kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated + result = [self.keyValueStore getBool:kisCensorshipCircumventionManuallyActivatedKey defaultValue:NO transaction:transaction]; }]; @@ -130,9 +127,7 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = - (void)setIsCensorshipCircumventionManuallyActivated:(BOOL)value { [self.databaseStorage writeWithBlock:^(SDSAnyWriteTransaction *transaction) { - [self.keyValueStore setBool:value - key:kOWSPrimaryStorage_isCensorshipCircumventionManuallyActivated - transaction:transaction]; + [self.keyValueStore setBool:value key:kisCensorshipCircumventionManuallyActivatedKey transaction:transaction]; }]; [self updateIsCensorshipCircumventionActive]; @@ -142,7 +137,7 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = { __block BOOL result; [self.databaseStorage readWithBlock:^(SDSAnyReadTransaction *transaction) { - result = [self.keyValueStore getBool:kOWSPrimaryStorage_isCensorshipCircumventionManuallyDisabled + result = [self.keyValueStore getBool:kisCensorshipCircumventionManuallyDisabledKey defaultValue:NO transaction:transaction]; }]; @@ -152,9 +147,7 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = - (void)setIsCensorshipCircumventionManuallyDisabled:(BOOL)value { [self.databaseStorage writeWithBlock:^(SDSAnyWriteTransaction *transaction) { - [self.keyValueStore setBool:value - key:kOWSPrimaryStorage_isCensorshipCircumventionManuallyDisabled - transaction:transaction]; + [self.keyValueStore setBool:value key:kisCensorshipCircumventionManuallyDisabledKey transaction:transaction]; }]; [self updateIsCensorshipCircumventionActive]; @@ -399,8 +392,7 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = { __block NSString *_Nullable result; [self.databaseStorage readWithBlock:^(SDSAnyReadTransaction *transaction) { - result = [self.keyValueStore getString:kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode - transaction:transaction]; + result = [self.keyValueStore getString:kManualCensorshipCircumventionCountryCodeKey transaction:transaction]; }]; return result; } @@ -408,9 +400,7 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = - (void)setManualCensorshipCircumventionCountryCode:(nullable NSString *)value { [self.databaseStorage writeWithBlock:^(SDSAnyWriteTransaction *transaction) { - [self.keyValueStore setString:value - key:kOWSPrimaryStorage_ManualCensorshipCircumventionCountryCode - transaction:transaction]; + [self.keyValueStore setString:value key:kManualCensorshipCircumventionCountryCodeKey transaction:transaction]; }]; } From 852a0f2f3559d7d717f4893b83519b2533d8b1dd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Aug 2019 11:57:09 -0300 Subject: [PATCH 5/7] Remove YDB & primary storage usage. --- .../AxolotlStore/SSKSignedPreKeyStore.h | 1 - SignalServiceKit/src/Storage/BaseModel.h | 6 --- .../src/Storage/TSYapDatabaseObject.h | 11 ------ .../src/Storage/TSYapDatabaseObject.m | 39 ------------------- 4 files changed, 57 deletions(-) diff --git a/SignalServiceKit/src/Storage/AxolotlStore/SSKSignedPreKeyStore.h b/SignalServiceKit/src/Storage/AxolotlStore/SSKSignedPreKeyStore.h index 065b936e9f..487072f085 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/SSKSignedPreKeyStore.h +++ b/SignalServiceKit/src/Storage/AxolotlStore/SSKSignedPreKeyStore.h @@ -2,7 +2,6 @@ // Copyright (c) 2019 Open Whisper Systems. All rights reserved. // -#import "OWSPrimaryStorage.h" #import NS_ASSUME_NONNULL_BEGIN diff --git a/SignalServiceKit/src/Storage/BaseModel.h b/SignalServiceKit/src/Storage/BaseModel.h index fe57c64f2d..71aeff40fb 100644 --- a/SignalServiceKit/src/Storage/BaseModel.h +++ b/SignalServiceKit/src/Storage/BaseModel.h @@ -24,12 +24,6 @@ NS_ASSUME_NONNULL_BEGIN + (void)enumerateCollectionObjectsUsingBlock:(void (^)(id obj, BOOL *stop))block NS_UNAVAILABLE; + (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction usingBlock:(void (^)(id object, BOOL *stop))block NS_UNAVAILABLE; -- (YapDatabaseConnection *)dbReadConnection NS_UNAVAILABLE; -+ (YapDatabaseConnection *)dbReadConnection NS_UNAVAILABLE; -- (YapDatabaseConnection *)dbReadWriteConnection NS_UNAVAILABLE; -+ (YapDatabaseConnection *)dbReadWriteConnection NS_UNAVAILABLE; -- (OWSPrimaryStorage *)primaryStorage NS_UNAVAILABLE; -+ (OWSPrimaryStorage *)primaryStorage NS_UNAVAILABLE; + (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction NS_UNAVAILABLE; + (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID NS_UNAVAILABLE; diff --git a/SignalServiceKit/src/Storage/TSYapDatabaseObject.h b/SignalServiceKit/src/Storage/TSYapDatabaseObject.h index 24d36e719e..f9acadcbe5 100644 --- a/SignalServiceKit/src/Storage/TSYapDatabaseObject.h +++ b/SignalServiceKit/src/Storage/TSYapDatabaseObject.h @@ -65,17 +65,6 @@ NS_ASSUME_NONNULL_BEGIN + (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction usingBlock:(void (^)(id object, BOOL *stop))block; -/** - * @return Shared database connections for reading and writing. - */ -- (YapDatabaseConnection *)dbReadConnection; -+ (YapDatabaseConnection *)dbReadConnection; -- (YapDatabaseConnection *)dbReadWriteConnection; -+ (YapDatabaseConnection *)dbReadWriteConnection; - -- (OWSPrimaryStorage *)primaryStorage; -+ (OWSPrimaryStorage *)primaryStorage; - @property (nonatomic, readonly) SDSDatabaseStorage *databaseStorage; @property (class, nonatomic, readonly) SDSDatabaseStorage *databaseStorage; diff --git a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m index b60b317093..72120104fa 100644 --- a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m +++ b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m @@ -87,47 +87,8 @@ NS_ASSUME_NONNULL_BEGIN }]; } -- (YapDatabaseConnection *)dbReadConnection -{ - return [[self class] dbReadConnection]; -} - -- (YapDatabaseConnection *)dbReadWriteConnection -{ - return [[self class] dbReadWriteConnection]; -} - -- (OWSPrimaryStorage *)primaryStorage -{ - return [[self class] primaryStorage]; -} - #pragma mark Class Methods -+ (YapDatabaseConnection *)dbReadConnection -{ - OWSJanksUI(); - - // We use TSYapDatabaseObject's dbReadWriteConnection (not OWSPrimaryStorage's - // dbReadConnection) for consistency, since we tend to [TSYapDatabaseObject - // save] and want to write to the same connection we read from. To get true - // consistency, we'd want to update entities by reading & writing from within - // the same transaction, but that'll be a big refactor. - return self.dbReadWriteConnection; -} - -+ (YapDatabaseConnection *)dbReadWriteConnection -{ - OWSJanksUI(); - - return SSKEnvironment.shared.objectReadWriteConnection; -} - -+ (OWSPrimaryStorage *)primaryStorage -{ - return [OWSPrimaryStorage sharedManager]; -} - - (SDSDatabaseStorage *)databaseStorage { return SDSDatabaseStorage.shared; From 6ba3e26e9e3b304499d0366414de41c97ca9de50 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Aug 2019 12:05:03 -0300 Subject: [PATCH 6/7] Remove YDB & primary storage usage. --- .../src/Storage/TSYapDatabaseObject.h | 44 ------- .../src/Storage/TSYapDatabaseObject.m | 115 ------------------ 2 files changed, 159 deletions(-) diff --git a/SignalServiceKit/src/Storage/TSYapDatabaseObject.h b/SignalServiceKit/src/Storage/TSYapDatabaseObject.h index f9acadcbe5..f79ef78f41 100644 --- a/SignalServiceKit/src/Storage/TSYapDatabaseObject.h +++ b/SignalServiceKit/src/Storage/TSYapDatabaseObject.h @@ -42,26 +42,11 @@ NS_ASSUME_NONNULL_BEGIN * * @return The number of keys in the classes collection. */ -+ (NSUInteger)numberOfKeysInCollection; + (NSUInteger)numberOfKeysInCollectionWithTransaction:(YapDatabaseReadTransaction *)transaction; -/** - * Removes all objects in the classes collection. - */ -+ (void)removeAllObjectsInCollection; - -/** - * A memory intesive method to get all objects in the collection. You should prefer using enumeration over this method - * whenever feasible. See `enumerateObjectsInCollectionUsingBlock` - * - * @return All objects in the classes collection. - */ -+ (NSArray *)allObjectsInCollection; - /** * Enumerates all objects in collection. */ -+ (void)enumerateCollectionObjectsUsingBlock:(void (^)(id obj, BOOL *stop))block; + (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction usingBlock:(void (^)(id object, BOOL *stop))block; @@ -79,32 +64,13 @@ NS_ASSUME_NONNULL_BEGIN + (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction NS_SWIFT_NAME(fetch(uniqueId:transaction:)); -+ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID NS_SWIFT_NAME(fetch(uniqueId:)); - -/** - * Saves the object with the shared readWrite connection. - * - * This method will block if another readWrite transaction is open. - */ -- (void)save; /** * Assign the latest persisted values from the database. */ -- (void)reload; - (void)reloadWithTransaction:(YapDatabaseReadTransaction *)transaction; - (void)reloadWithTransaction:(YapDatabaseReadTransaction *)transaction ignoreMissing:(BOOL)ignoreMissing; -/** - * Saves the object with the shared readWrite connection - does not block. - * - * Be mindful that this method may clobber other changes persisted - * while waiting to open the readWrite transaction. - * - * @param completionBlock is called on the main thread - */ -- (void)saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock; - /** * Saves the object with the provided transaction * @@ -118,7 +84,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSString *uniqueId; - (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; -- (void)remove; #pragma mark - Write Hooks @@ -138,25 +103,16 @@ NS_ASSUME_NONNULL_BEGIN // GRDB TODO: Ensure these ydb_ methods are only be used before // and during the ydb-to-grdb migration. -+ (NSUInteger)ydb_numberOfKeysInCollection; + (NSUInteger)ydb_numberOfKeysInCollectionWithTransaction:(YapDatabaseReadTransaction *)transaction; -+ (void)ydb_removeAllObjectsInCollection; -+ (NSArray *)ydb_allObjectsInCollection; -+ (void)ydb_enumerateCollectionObjectsUsingBlock:(void (^)(id obj, BOOL *stop))block; + (void)ydb_enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction usingBlock:(void (^)(id object, BOOL *stop))block; + (nullable instancetype)ydb_fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction NS_SWIFT_NAME(ydb_fetch(uniqueId:transaction:)); -+ (nullable instancetype)ydb_fetchObjectWithUniqueID:(NSString *)uniqueID NS_SWIFT_NAME(ydb_fetch(uniqueId:)); -- (void)ydb_save; -- (void)ydb_reload; - (void)ydb_reloadWithTransaction:(YapDatabaseReadTransaction *)transaction; - (void)ydb_reloadWithTransaction:(YapDatabaseReadTransaction *)transaction ignoreMissing:(BOOL)ignoreMissing; -- (void)ydb_saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock; - (void)ydb_saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; - (void)ydb_removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction; -- (void)ydb_remove; @end diff --git a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m index 72120104fa..4702902c0e 100644 --- a/SignalServiceKit/src/Storage/TSYapDatabaseObject.m +++ b/SignalServiceKit/src/Storage/TSYapDatabaseObject.m @@ -60,33 +60,11 @@ NS_ASSUME_NONNULL_BEGIN [transaction setObject:self forKey:self.uniqueId inCollection:[[self class] collection]]; } -- (void)save -{ - [[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [self saveWithTransaction:transaction]; - }]; -} - -- (void)saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock -{ - [[self dbReadWriteConnection] asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { - [self saveWithTransaction:transaction]; - } - completionBlock:completionBlock]; -} - - (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { [transaction removeObjectForKey:self.uniqueId inCollection:[[self class] collection]]; } -- (void)remove -{ - [[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [self removeWithTransaction:transaction]; - }]; -} - #pragma mark Class Methods - (SDSDatabaseStorage *)databaseStorage @@ -104,36 +82,11 @@ NS_ASSUME_NONNULL_BEGIN return NSStringFromClass([self class]); } -+ (NSUInteger)numberOfKeysInCollection -{ - __block NSUInteger count; - [[self dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) { - count = [self numberOfKeysInCollectionWithTransaction:transaction]; - }]; - return count; -} - + (NSUInteger)numberOfKeysInCollectionWithTransaction:(YapDatabaseReadTransaction *)transaction { return [transaction numberOfKeysInCollection:[self collection]]; } -+ (NSArray *)allObjectsInCollection -{ - __block NSMutableArray *all = [[NSMutableArray alloc] initWithCapacity:[self numberOfKeysInCollection]]; - [self enumerateCollectionObjectsUsingBlock:^(id object, BOOL *stop) { - [all addObject:object]; - }]; - return [all copy]; -} - -+ (void)enumerateCollectionObjectsUsingBlock:(void (^)(id object, BOOL *stop))block -{ - [[self dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) { - [self enumerateCollectionObjectsWithTransaction:transaction usingBlock:block]; - }]; -} - + (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction usingBlock:(void (^)(id object, BOOL *stop))block { @@ -146,37 +99,14 @@ NS_ASSUME_NONNULL_BEGIN [transaction enumerateRowsInCollection:[self collection] usingBlock:yapBlock]; } -+ (void)removeAllObjectsInCollection -{ - [[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { - [transaction removeAllObjectsInCollection:[self collection]]; - }]; -} - + (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction { return [transaction objectForKey:uniqueID inCollection:[self collection]]; } -+ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID -{ - __block id _Nullable object = nil; - [[self dbReadConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) { - object = [transaction objectForKey:uniqueID inCollection:[self collection]]; - }]; - return object; -} - #pragma mark Reload -- (void)reload -{ - [self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { - [self reloadWithTransaction:transaction]; - }]; -} - - (void)reloadWithTransaction:(YapDatabaseReadTransaction *)transaction { [self reloadWithTransaction:transaction ignoreMissing:NO]; @@ -234,11 +164,6 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - YDB Deprecation -+ (NSUInteger)ydb_numberOfKeysInCollection -{ - return [self numberOfKeysInCollection]; -} - + (NSUInteger)ydb_numberOfKeysInCollectionWithTransaction:(YapDatabaseReadTransaction *)transaction { OWSAssertDebug(transaction); @@ -246,21 +171,6 @@ NS_ASSUME_NONNULL_BEGIN return [self numberOfKeysInCollectionWithTransaction:transaction]; } -+ (void)ydb_removeAllObjectsInCollection -{ - [self removeAllObjectsInCollection]; -} - -+ (NSArray *)ydb_allObjectsInCollection -{ - return [self allObjectsInCollection]; -} - -+ (void)ydb_enumerateCollectionObjectsUsingBlock:(void (^)(id obj, BOOL *stop))block -{ - return [self enumerateCollectionObjectsUsingBlock:block]; -} - + (void)ydb_enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction usingBlock:(void (^)(id object, BOOL *stop))block { @@ -277,21 +187,6 @@ NS_ASSUME_NONNULL_BEGIN return [self fetchObjectWithUniqueID:uniqueID transaction:transaction]; } -+ (nullable instancetype)ydb_fetchObjectWithUniqueID:(NSString *)uniqueID -{ - return [self fetchObjectWithUniqueID:uniqueID]; -} - -- (void)ydb_save -{ - [self save]; -} - -- (void)ydb_reload -{ - [self reload]; -} - - (void)ydb_reloadWithTransaction:(YapDatabaseReadTransaction *)transaction { OWSAssertDebug(transaction); @@ -306,11 +201,6 @@ NS_ASSUME_NONNULL_BEGIN [self reloadWithTransaction:transaction ignoreMissing:ignoreMissing]; } -- (void)ydb_saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock -{ - [self saveAsyncWithCompletionBlock:completionBlock]; -} - - (void)ydb_saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssertDebug(transaction); @@ -325,11 +215,6 @@ NS_ASSUME_NONNULL_BEGIN [self removeWithTransaction:transaction]; } -- (void)ydb_remove -{ - [self remove]; -} - @end NS_ASSUME_NONNULL_END From 5f92ccc5e2c40e448a4bd9f376026e656a475d08 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 13 Aug 2019 12:08:40 -0300 Subject: [PATCH 7/7] Remove YDB & primary storage usage. --- SignalServiceKit/src/Storage/BaseModel.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/SignalServiceKit/src/Storage/BaseModel.h b/SignalServiceKit/src/Storage/BaseModel.h index 71aeff40fb..90883906ad 100644 --- a/SignalServiceKit/src/Storage/BaseModel.h +++ b/SignalServiceKit/src/Storage/BaseModel.h @@ -17,25 +17,16 @@ NS_ASSUME_NONNULL_BEGIN // This will break Swift usage and generate warnings for Obj-C usage. // Note: this functionality can still be accessed (for example by the // SDS model extensions) via the ydb_ methods of TSYapDatabaseObject. -+ (NSUInteger)numberOfKeysInCollection NS_UNAVAILABLE; + (NSUInteger)numberOfKeysInCollectionWithTransaction:(YapDatabaseReadTransaction *)transaction NS_UNAVAILABLE; -+ (void)removeAllObjectsInCollection NS_UNAVAILABLE; -+ (NSArray *)allObjectsInCollection NS_UNAVAILABLE; -+ (void)enumerateCollectionObjectsUsingBlock:(void (^)(id obj, BOOL *stop))block NS_UNAVAILABLE; + (void)enumerateCollectionObjectsWithTransaction:(YapDatabaseReadTransaction *)transaction usingBlock:(void (^)(id object, BOOL *stop))block NS_UNAVAILABLE; + (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID transaction:(YapDatabaseReadTransaction *)transaction NS_UNAVAILABLE; -+ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID NS_UNAVAILABLE; -- (void)save NS_UNAVAILABLE; -- (void)reload NS_UNAVAILABLE; - (void)reloadWithTransaction:(YapDatabaseReadTransaction *)transaction NS_UNAVAILABLE; - (void)reloadWithTransaction:(YapDatabaseReadTransaction *)transaction ignoreMissing:(BOOL)ignoreMissing NS_UNAVAILABLE; -- (void)saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock NS_UNAVAILABLE; - (void)saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction NS_UNAVAILABLE; - (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction NS_UNAVAILABLE; -- (void)remove NS_UNAVAILABLE; @end