Reduce number of database views.

// FREEBIE.
pull/1/head
Matthew Chen 8 years ago
parent d1097c3610
commit 575d631123

@ -5,8 +5,8 @@ target 'Signal' do
pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git'
pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git'
#pod 'AxolotlKit', path: '../SignalProtocolKit' #pod 'AxolotlKit', path: '../SignalProtocolKit'
pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git' #pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git'
#pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'SignalServiceKit', path: '../SignalServiceKit'
pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu' pod 'JSQMessagesViewController', git: 'https://github.com/WhisperSystems/JSQMessagesViewController.git', branch: 'mkirk/position-edit-menu'
#pod 'JSQMessagesViewController' path: '../JSQMessagesViewController' #pod 'JSQMessagesViewController' path: '../JSQMessagesViewController'
pod 'PureLayout' pod 'PureLayout'

@ -112,7 +112,7 @@ DEPENDENCIES:
- JSQMessagesViewController (from `https://github.com/WhisperSystems/JSQMessagesViewController.git`, branch `mkirk/position-edit-menu`) - JSQMessagesViewController (from `https://github.com/WhisperSystems/JSQMessagesViewController.git`, branch `mkirk/position-edit-menu`)
- PureLayout - PureLayout
- Reachability - Reachability
- SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`) - SignalServiceKit (from `../SignalServiceKit`)
- SocketRocket (from `https://github.com/facebook/SocketRocket.git`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`)
EXTERNAL SOURCES: EXTERNAL SOURCES:
@ -122,7 +122,7 @@ EXTERNAL SOURCES:
:branch: mkirk/position-edit-menu :branch: mkirk/position-edit-menu
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git :git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit: SignalServiceKit:
:git: https://github.com/WhisperSystems/SignalServiceKit.git :path: ../SignalServiceKit
SocketRocket: SocketRocket:
:git: https://github.com/facebook/SocketRocket.git :git: https://github.com/facebook/SocketRocket.git
@ -133,9 +133,6 @@ CHECKOUT OPTIONS:
JSQMessagesViewController: JSQMessagesViewController:
:commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308 :commit: 7054e4b13ee5bcd6d524adb6dc9a726e8c466308
:git: https://github.com/WhisperSystems/JSQMessagesViewController.git :git: https://github.com/WhisperSystems/JSQMessagesViewController.git
SignalServiceKit:
:commit: d8199a444f643d142824d6e7b7c507a1b2c8032d
:git: https://github.com/WhisperSystems/SignalServiceKit.git
SocketRocket: SocketRocket:
:commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf :commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf
:git: https://github.com/facebook/SocketRocket.git :git: https://github.com/facebook/SocketRocket.git
@ -161,6 +158,6 @@ SPEC CHECKSUMS:
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266 YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
PODFILE CHECKSUM: 89fd7aee1e2b0ca592ecc9dba0389e57b70f959b PODFILE CHECKSUM: 6e5d90a9603eb043b395213fd8a29037d2276a8f
COCOAPODS: 1.2.1 COCOAPODS: 1.2.1

@ -113,12 +113,14 @@ NS_ASSUME_NONNULL_BEGIN
[storageManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [storageManager.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
const int kMaxBlockOfferOutgoingMessageCount = 10; const int kMaxBlockOfferOutgoingMessageCount = 10;
// Find any existing "dynamic" interactions. // Find any "dynamic" interactions and safety number changes.
__block OWSAddToContactsOfferMessage *existingAddToContactsOffer = nil; __block OWSAddToContactsOfferMessage *existingAddToContactsOffer = nil;
__block OWSUnknownContactBlockOfferMessage *existingBlockOffer = nil; __block OWSUnknownContactBlockOfferMessage *existingBlockOffer = nil;
__block TSUnreadIndicatorInteraction *existingUnreadIndicator = nil; __block TSUnreadIndicatorInteraction *existingUnreadIndicator = nil;
NSMutableArray<TSInvalidIdentityKeyErrorMessage *> *blockingSafetyNumberChanges = [NSMutableArray new];
NSMutableArray<TSInteraction *> *nonBlockingSafetyNumberChanges = [NSMutableArray new];
// We use different views for performance reasons. // We use different views for performance reasons.
[[transaction ext:TSDynamicMessagesDatabaseViewExtensionName] [[transaction ext:TSThreadSpecialMessagesDatabaseViewExtensionName]
enumerateRowsInGroup:thread.uniqueId enumerateRowsInGroup:thread.uniqueId
usingBlock:^( usingBlock:^(
NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) { NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) {
@ -132,30 +134,14 @@ NS_ASSUME_NONNULL_BEGIN
} else if ([object isKindOfClass:[TSUnreadIndicatorInteraction class]]) { } else if ([object isKindOfClass:[TSUnreadIndicatorInteraction class]]) {
OWSAssert(!existingUnreadIndicator); OWSAssert(!existingUnreadIndicator);
existingUnreadIndicator = (TSUnreadIndicatorInteraction *)object; existingUnreadIndicator = (TSUnreadIndicatorInteraction *)object;
} else { } else if ([object isKindOfClass:[TSInvalidIdentityKeyErrorMessage class]]) {
DDLogError(@"Unexpected dynamic interaction type: %@", [object class]);
OWSAssert(0);
}
}];
// Find any existing safety number changes.
//
// We use different views for performance reasons.
NSMutableArray<TSInvalidIdentityKeyErrorMessage *> *blockingSafetyNumberChanges = [NSMutableArray new];
NSMutableArray<TSInteraction *> *nonBlockingSafetyNumberChanges = [NSMutableArray new];
[[transaction ext:TSSafetyNumberChangeDatabaseViewExtensionName]
enumerateRowsInGroup:thread.uniqueId
usingBlock:^(
NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) {
if ([object isKindOfClass:[TSInvalidIdentityKeyErrorMessage class]]) {
[blockingSafetyNumberChanges addObject:object]; [blockingSafetyNumberChanges addObject:object];
} else if ([object isKindOfClass:[TSErrorMessage class]]) { } else if ([object isKindOfClass:[TSErrorMessage class]]) {
TSErrorMessage *errorMessage = (TSErrorMessage *)object; TSErrorMessage *errorMessage = (TSErrorMessage *)object;
OWSAssert(errorMessage.errorType == TSErrorMessageNonBlockingIdentityChange); OWSAssert(errorMessage.errorType == TSErrorMessageNonBlockingIdentityChange);
[nonBlockingSafetyNumberChanges addObject:errorMessage]; [nonBlockingSafetyNumberChanges addObject:errorMessage];
} else { } else {
DDLogError(@"Unexpected interaction type: %@", [object class]); DDLogError(@"Unexpected dynamic interaction type: %@", [object class]);
OWSAssert(0); OWSAssert(0);
} }
}]; }];
@ -177,10 +163,21 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
TSIncomingMessage *firstIncomingMessage = __block TSMessage *firstMessage = nil;
[[transaction ext:TSThreadIncomingMessageDatabaseViewExtensionName] firstObjectInGroup:thread.uniqueId]; [[transaction ext:TSMessageDatabaseViewExtensionName]
TSOutgoingMessage *firstOutgoingMessage = enumerateRowsInGroup:thread.uniqueId
[[transaction ext:TSThreadOutgoingMessageDatabaseViewExtensionName] firstObjectInGroup:thread.uniqueId]; usingBlock:^(
NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) {
OWSAssert([object isKindOfClass:[TSInteraction class]]);
if ([object isKindOfClass:[TSIncomingMessage class]] ||
[object isKindOfClass:[TSOutgoingMessage class]]) {
firstMessage = (TSMessage *)object;
*stop = YES;
}
}];
NSUInteger outgoingMessageCount = NSUInteger outgoingMessageCount =
[[transaction ext:TSThreadOutgoingMessageDatabaseViewExtensionName] numberOfItemsInGroup:thread.uniqueId]; [[transaction ext:TSThreadOutgoingMessageDatabaseViewExtensionName] numberOfItemsInGroup:thread.uniqueId];
NSUInteger threadMessageCount = NSUInteger threadMessageCount =
@ -270,12 +267,6 @@ NS_ASSUME_NONNULL_BEGIN
} }
OWSAssert((result.firstUnseenInteractionTimestamp != nil) == (result.unreadIndicatorPosition != nil)); OWSAssert((result.firstUnseenInteractionTimestamp != nil) == (result.unreadIndicatorPosition != nil));
TSMessage *firstMessage = firstIncomingMessage;
if (!firstMessage
|| (firstOutgoingMessage && [firstOutgoingMessage compareForSorting:firstMessage] == NSOrderedAscending)) {
firstMessage = firstOutgoingMessage;
}
BOOL shouldHaveBlockOffer = YES; BOOL shouldHaveBlockOffer = YES;
BOOL shouldHaveAddToContactsOffer = YES; BOOL shouldHaveAddToContactsOffer = YES;
@ -314,9 +305,7 @@ NS_ASSUME_NONNULL_BEGIN
shouldHaveBlockOffer = NO; shouldHaveBlockOffer = NO;
} }
BOOL hasOutgoingBeforeIncomingInteraction = (firstOutgoingMessage BOOL hasOutgoingBeforeIncomingInteraction = [firstMessage isKindOfClass:[TSOutgoingMessage class]];
&& (!firstIncomingMessage ||
[firstOutgoingMessage compareForSorting:firstIncomingMessage] == NSOrderedAscending));
if (hasOutgoingBeforeIncomingInteraction) { if (hasOutgoingBeforeIncomingInteraction) {
// If there is an outgoing message before an incoming message // If there is an outgoing message before an incoming message
// the local user initiated this conversation, don't show a block offer. // the local user initiated this conversation, don't show a block offer.

Loading…
Cancel
Save