Clean up TSStorageManager usage.

pull/1/head
Matthew Chen 7 years ago
parent 9258b0883e
commit d3efb2e1c9

@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Database extensions required for class to work.
*/
- (void)asyncRegisterDatabaseExtensions;
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(TSStorageManager *)storageManager;
/**
* Only use the sync version for testing, generally we'll want to register extensions async

@ -96,7 +96,7 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
#pragma mark - YapDatabaseExtension
- (YapDatabaseSecondaryIndex *)indexDatabaseExtension
+ (YapDatabaseSecondaryIndex *)indexDatabaseExtension
{
YapDatabaseSecondaryIndexSetup *setup = [YapDatabaseSecondaryIndexSetup new];
[setup addColumn:OWSFailedAttachmentDownloadsJobAttachmentStateColumn
@ -121,21 +121,21 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
// Useful for tests, don't use in app startup path because it's slow.
- (void)blockingRegisterDatabaseExtensions
{
[self.storageManager registerExtension:[self indexDatabaseExtension]
[self.storageManager registerExtension:[self.class indexDatabaseExtension]
withName:OWSFailedAttachmentDownloadsJobAttachmentStateIndex];
}
- (void)asyncRegisterDatabaseExtensions
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(TSStorageManager *)storageManager
{
[self.storageManager asyncRegisterExtension:[self indexDatabaseExtension]
withName:OWSFailedAttachmentDownloadsJobAttachmentStateIndex
completionBlock:^(BOOL ready) {
if (ready) {
DDLogDebug(@"%@ completed registering extension async.", self.logTag);
} else {
DDLogError(@"%@ failed registering extension async.", self.logTag);
}
}];
[storageManager asyncRegisterExtension:[self indexDatabaseExtension]
withName:OWSFailedAttachmentDownloadsJobAttachmentStateIndex
completionBlock:^(BOOL ready) {
if (ready) {
DDLogDebug(@"%@ completed registering extension async.", self.logTag);
} else {
DDLogError(@"%@ failed registering extension async.", self.logTag);
}
}];
}
@end

@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Database extensions required for class to work.
*/
- (void)asyncRegisterDatabaseExtensions;
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(TSStorageManager *)storageManager;
/**
* Only use the sync version for testing, generally we'll want to register extensions async

@ -105,7 +105,7 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
#pragma mark - YapDatabaseExtension
- (YapDatabaseSecondaryIndex *)indexDatabaseExtension
+ (YapDatabaseSecondaryIndex *)indexDatabaseExtension
{
YapDatabaseSecondaryIndexSetup *setup = [YapDatabaseSecondaryIndexSetup new];
[setup addColumn:OWSFailedMessagesJobMessageStateColumn withType:YapDatabaseSecondaryIndexTypeInteger];
@ -130,21 +130,21 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
// Useful for tests, don't use in app startup path because it's slow.
- (void)blockingRegisterDatabaseExtensions
{
[self.storageManager registerExtension:[self indexDatabaseExtension]
[self.storageManager registerExtension:[self.class indexDatabaseExtension]
withName:OWSFailedMessagesJobMessageStateIndex];
}
- (void)asyncRegisterDatabaseExtensions
+ (void)asyncRegisterDatabaseExtensionsWithStorageManager:(TSStorageManager *)storageManager
{
[self.storageManager asyncRegisterExtension:[self indexDatabaseExtension]
withName:OWSFailedMessagesJobMessageStateIndex
completionBlock:^(BOOL ready) {
if (ready) {
DDLogDebug(@"%@ completed registering extension async.", self.logTag);
} else {
DDLogError(@"%@ failed registering extension async.", self.logTag);
}
}];
[storageManager asyncRegisterExtension:[self indexDatabaseExtension]
withName:OWSFailedMessagesJobMessageStateIndex
completionBlock:^(BOOL ready) {
if (ready) {
DDLogDebug(@"%@ completed registering extension async.", self.logTag);
} else {
DDLogError(@"%@ failed registering extension async.", self.logTag);
}
}];
}
@end

@ -2,6 +2,7 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSStorageKeys.h"
#import "TSStorageManager+PreKeyStore.h"
#import "TSStorageManager+keyFromIntLong.h"
#import "YapDatabaseConnection+OWS.h"

@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Must be called before using this finder.
*/
- (void)asyncRegisterExtension;
+ (void)asyncRegisterExtensionWithStorageManager:(TSStorageManager *)storageManager;
/**
* Detects existance of a duplicate incoming message.

@ -62,7 +62,7 @@ NSString *const OWSIncomingMessageFinderColumnSourceDeviceId = @"OWSIncomingMess
#pragma mark - YAP integration
- (YapDatabaseSecondaryIndex *)indexExtension
+ (YapDatabaseSecondaryIndex *)indexExtension
{
YapDatabaseSecondaryIndexSetup *setup = [YapDatabaseSecondaryIndexSetup new];
@ -92,21 +92,21 @@ NSString *const OWSIncomingMessageFinderColumnSourceDeviceId = @"OWSIncomingMess
return [[YapDatabaseSecondaryIndex alloc] initWithSetup:setup handler:handler];
}
- (void)asyncRegisterExtension
+ (void)asyncRegisterExtensionWithStorageManager:(TSStorageManager *)storageManager
{
DDLogInfo(@"%@ registering async.", self.logTag);
[self.storageManager asyncRegisterExtension:self.indexExtension
withName:OWSIncomingMessageFinderExtensionName
completionBlock:^(BOOL ready) {
DDLogInfo(@"%@ finished registering async.", self.logTag);
}];
[storageManager asyncRegisterExtension:self.indexExtension
withName:OWSIncomingMessageFinderExtensionName
completionBlock:^(BOOL ready) {
DDLogInfo(@"%@ finished registering async.", self.logTag);
}];
}
// We should not normally hit this, as we should have prefer registering async, but it is useful for testing.
- (void)registerExtension
{
DDLogError(@"%@ registering SYNC. We should prefer async when possible.", self.logTag);
[self.storageManager registerExtension:self.indexExtension withName:OWSIncomingMessageFinderExtensionName];
[self.storageManager registerExtension:self.class.indexExtension withName:OWSIncomingMessageFinderExtensionName];
}
#pragma mark - instance methods

@ -3,7 +3,6 @@
//
#import "OWSStorage.h"
#import "TSStorageKeys.h"
NS_ASSUME_NONNULL_BEGIN

@ -11,13 +11,8 @@
#import "OWSFileSystem.h"
#import "OWSIncomingMessageFinder.h"
#import "OWSMessageReceiver.h"
#import "SignalRecipient.h"
#import "TSAttachmentStream.h"
#import "TSDatabaseSecondaryIndexes.h"
#import "TSDatabaseView.h"
#import "TSInteraction.h"
#import "TSThread.h"
#import <YapDatabase/YapDatabaseRelationship.h>
NS_ASSUME_NONNULL_BEGIN
@ -110,14 +105,11 @@ NSString *const TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory
[TSDatabaseView asyncRegisterThreadSpecialMessagesDatabaseView];
// Register extensions which aren't essential for rendering threads async.
[[OWSIncomingMessageFinder new] asyncRegisterExtension];
[OWSIncomingMessageFinder asyncRegisterExtensionWithStorageManager:self];
[TSDatabaseView asyncRegisterSecondaryDevicesDatabaseView];
[OWSDisappearingMessagesFinder asyncRegisterDatabaseExtensions:self];
OWSFailedMessagesJob *failedMessagesJob = [[OWSFailedMessagesJob alloc] initWithStorageManager:self];
[failedMessagesJob asyncRegisterDatabaseExtensions];
OWSFailedAttachmentDownloadsJob *failedAttachmentDownloadsMessagesJob =
[[OWSFailedAttachmentDownloadsJob alloc] initWithStorageManager:self];
[failedAttachmentDownloadsMessagesJob asyncRegisterDatabaseExtensions];
[OWSFailedMessagesJob asyncRegisterDatabaseExtensionsWithStorageManager:self];
[OWSFailedAttachmentDownloadsJob asyncRegisterDatabaseExtensionsWithStorageManager:self];
// NOTE: [TSDatabaseView asyncRegistrationCompletion] ensures that
// DatabaseViewRegistrationCompleteNotification is not fired until all

Loading…
Cancel
Save