Addresses some performance issues on loading from database.

pull/1/head
Frederic Jacobs 10 years ago
parent 82a9029c37
commit 1f61291e0c

@ -184,8 +184,9 @@ typedef enum : NSUInteger {
[self updateRangeOptionsForPage:self.page]; [self updateRangeOptionsForPage:self.page];
[self.uiDatabaseConnection beginLongLivedReadTransaction]; [self.uiDatabaseConnection beginLongLivedReadTransaction];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.uiDatabaseConnection asyncReadWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.messageMappings updateWithTransaction:transaction]; [self.messageMappings updateWithTransaction:transaction];
[self.collectionView reloadData];
}]; }];
[self initializeCollectionViewLayout]; [self initializeCollectionViewLayout];
@ -1378,7 +1379,7 @@ typedef enum : NSUInteger {
} }
} }
} completion:^(BOOL success) { } completion:^(BOOL success) {
if (success) { if (!success) {
[self.collectionView.collectionViewLayout invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]]; [self.collectionView.collectionViewLayout invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
[self.collectionView reloadData]; [self.collectionView reloadData];
} }
@ -1513,7 +1514,7 @@ typedef enum : NSUInteger {
} }
- (void)markAllMessagesAsRead { - (void)markAllMessagesAsRead {
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self.thread markAllAsReadWithTransaction:transaction]; [self.thread markAllAsReadWithTransaction:transaction];
}]; }];
} }
@ -1612,8 +1613,11 @@ typedef enum : NSUInteger {
- (void)saveDraft { - (void)saveDraft {
if (self.inputToolbar.hidden == NO) { if (self.inputToolbar.hidden == NO) {
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { __block TSThread *thread = _thread;
[_thread setDraft:self.inputToolbar.contentView.textView.text transaction:transaction]; __block NSString *currentDraft = self.inputToolbar.contentView.textView.text;
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[thread setDraft:currentDraft transaction:transaction];
}]; }];
} }
} }

@ -78,7 +78,6 @@ static NSString* const kShowSignupFlowSegue = @"showSignupFlow";
} onThread:[NSThread mainThread] untilCancelled:nil]; } onThread:[NSThread mainThread] untilCancelled:nil];
self.title = NSLocalizedString(@"CONVERSATIONS_VIEW_TITLE", @""); self.title = NSLocalizedString(@"CONVERSATIONS_VIEW_TITLE", @"");
} }
-(void)viewWillAppear:(BOOL)animated -(void)viewWillAppear:(BOOL)animated
@ -282,12 +281,14 @@ static NSString* const kShowSignupFlowSegue = @"showSignupFlow";
view:TSThreadDatabaseViewExtensionName]; view:TSThreadDatabaseViewExtensionName];
[self.threadMappings setIsReversed:YES forGroup:grouping]; [self.threadMappings setIsReversed:YES forGroup:grouping];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction){ [self.uiDatabaseConnection asyncReadWithBlock:^(YapDatabaseReadTransaction *transaction){
[self.threadMappings updateWithTransaction:transaction]; [self.threadMappings updateWithTransaction:transaction];
}];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData]; [self.tableView reloadData];
[self checkIfEmptyView]; [self checkIfEmptyView];
});
}];
} }
#pragma mark Database delegates #pragma mark Database delegates

Loading…
Cancel
Save