Increase cache, remove dead code, add debug logging

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent b3cd6a112b
commit 1f63ce02a0

@ -947,6 +947,8 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
if (!_uiDatabaseConnection) { if (!_uiDatabaseConnection) {
_uiDatabaseConnection = [OWSPrimaryStorage.sharedManager newDatabaseConnection]; _uiDatabaseConnection = [OWSPrimaryStorage.sharedManager newDatabaseConnection];
// default is 250
_uiDatabaseConnection.objectCacheLimit = 500;
[_uiDatabaseConnection beginLongLivedReadTransaction]; [_uiDatabaseConnection beginLongLivedReadTransaction];
} }
return _uiDatabaseConnection; return _uiDatabaseConnection;

@ -65,13 +65,6 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
- (NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *)receivedMessagesForInvalidKey:(NSData *)key; - (NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *)receivedMessagesForInvalidKey:(NSData *)key;
/**
* Returns whether or not the thread has unread messages.
*
* @return YES if it has unread TSIncomingMessages, NO otherwise.
*/
- (BOOL)hasUnreadMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(hasUnreadMessages(transaction:));
- (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction - (NSUInteger)unreadMessageCountWithTransaction:(YapDatabaseReadTransaction *)transaction
NS_SWIFT_NAME(unreadMessageCount(transaction:)); NS_SWIFT_NAME(unreadMessageCount(transaction:));

@ -200,18 +200,6 @@ NS_ASSUME_NONNULL_BEGIN
return count; return count;
} }
- (BOOL)hasUnreadMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction
{
TSInteraction *interaction = [self lastInteractionWithTransaction:transaction];
BOOL hasUnread = NO;
if ([interaction isKindOfClass:[TSIncomingMessage class]]) {
hasUnread = ![(TSIncomingMessage *)interaction wasRead];
}
return hasUnread;
}
- (NSArray<id<OWSReadTracking>> *)unseenMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction - (NSArray<id<OWSReadTracking>> *)unseenMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
NSMutableArray<id<OWSReadTracking>> *messages = [NSMutableArray new]; NSMutableArray<id<OWSReadTracking>> *messages = [NSMutableArray new];
@ -245,13 +233,9 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert([self unseenMessagesWithTransaction:transaction].count < 1); OWSAssert([self unseenMessagesWithTransaction:transaction].count < 1);
} }
- (TSInteraction *)lastInteractionWithTransaction:(YapDatabaseReadTransaction *)transaction
{
return [[transaction ext:TSMessageDatabaseViewExtensionName] lastObjectInGroup:self.uniqueId];
}
- (TSInteraction *)lastInteractionForInboxWithTransaction:(YapDatabaseReadTransaction *)transaction - (TSInteraction *)lastInteractionForInboxWithTransaction:(YapDatabaseReadTransaction *)transaction
{ {
__block NSUInteger missedCount = 0;
__block TSInteraction *last = nil; __block TSInteraction *last = nil;
[[transaction ext:TSMessageDatabaseViewExtensionName] [[transaction ext:TSMessageDatabaseViewExtensionName]
enumerateRowsInGroup:self.uniqueId enumerateRowsInGroup:self.uniqueId
@ -261,10 +245,19 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert([object isKindOfClass:[TSInteraction class]]); OWSAssert([object isKindOfClass:[TSInteraction class]]);
missedCount++;
TSInteraction *interaction = (TSInteraction *)object; TSInteraction *interaction = (TSInteraction *)object;
if ([TSThread shouldInteractionAppearInInbox:interaction]) { if ([TSThread shouldInteractionAppearInInbox:interaction]) {
last = interaction; last = interaction;
// For long ignored threads, with lots of SN changes this can get really slow.
// I see this in development because I have a lot of long forgotten threads with members
// who's test devices are constantly reinstalled. We could add a purpose-built DB view,
// but I think in the real world this is rare to be a hotspot.
if (missedCount > 50) {
DDLogWarn(@"%@ found last interaction for inbox after skipping %tu items", self.logTag, missedCount);
}
*stop = YES; *stop = YES;
} }
}]; }];

Loading…
Cancel
Save