From 468f7524ef4cae740153525a6910c6091cec5b3d Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 1 Jun 2018 09:57:50 -0400 Subject: [PATCH] Revert "separate read/write db connections" This reverts commit 3e61741060e6a7c2a9891b46cf3abd567d33aa3a. --- .../ConversationViewController.m | 3 +- SignalMessaging/utils/ThreadUtil.h | 5 +- SignalMessaging/utils/ThreadUtil.m | 47 ++++--------------- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 65fe5a58a..169a54846 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -2471,8 +2471,7 @@ typedef enum : NSUInteger { [ThreadUtil ensureDynamicInteractionsForThread:self.thread contactsManager:self.contactsManager blockingManager:self.blockingManager - uiDatabaseConnection:self.uiDatabaseConnection - editingDatabaseConnection:self.editingDatabaseConnection + dbConnection:self.editingDatabaseConnection hideUnreadMessagesIndicator:self.hasClearedUnreadMessagesIndicator firstUnseenInteractionTimestamp:self.dynamicInteractions.firstUnseenInteractionTimestamp maxRangeSize:maxRangeSize]; diff --git a/SignalMessaging/utils/ThreadUtil.h b/SignalMessaging/utils/ThreadUtil.h index 152282b92..197cc1c67 100644 --- a/SignalMessaging/utils/ThreadUtil.h +++ b/SignalMessaging/utils/ThreadUtil.h @@ -102,10 +102,9 @@ NS_ASSUME_NONNULL_BEGIN + (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager blockingManager:(OWSBlockingManager *)blockingManager - uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection - editingDatabaseConnection:(YapDatabaseConnection *)editingDatabaseConnection + dbConnection:(YapDatabaseConnection *)dbConnection hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator - firstUnseenInteractionTimestamp:(nullable NSNumber *)firstUnseenInteractionTimestampParameter + firstUnseenInteractionTimestamp:(nullable NSNumber *)firstUnseenInteractionTimestamp maxRangeSize:(int)maxRangeSize; + (BOOL)shouldShowGroupProfileBannerInThread:(TSThread *)thread blockingManager:(OWSBlockingManager *)blockingManager; diff --git a/SignalMessaging/utils/ThreadUtil.m b/SignalMessaging/utils/ThreadUtil.m index e9eedd8b7..c5df4a72a 100644 --- a/SignalMessaging/utils/ThreadUtil.m +++ b/SignalMessaging/utils/ThreadUtil.m @@ -217,16 +217,14 @@ NS_ASSUME_NONNULL_BEGIN + (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager blockingManager:(OWSBlockingManager *)blockingManager - uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection - editingDatabaseConnection:(YapDatabaseConnection *)editingDatabaseConnection + dbConnection:(YapDatabaseConnection *)dbConnection hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator firstUnseenInteractionTimestamp: (nullable NSNumber *)firstUnseenInteractionTimestampParameter maxRangeSize:(int)maxRangeSize { OWSAssert(thread); - OWSAssert(uiDatabaseConnection); - OWSAssert(editingDatabaseConnection); + OWSAssert(dbConnection); OWSAssert(contactsManager); OWSAssert(blockingManager); OWSAssert(maxRangeSize > 0); @@ -249,8 +247,7 @@ NS_ASSUME_NONNULL_BEGIN ThreadDynamicInteractions *result = [ThreadDynamicInteractions new]; - NSMutableArray *writeBlocks = [NSMutableArray new]; - [uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { const int kMaxBlockOfferOutgoingMessageCount = 10; // Find any "dynamic" interactions and safety number changes. @@ -308,9 +305,7 @@ NS_ASSUME_NONNULL_BEGIN for (TSInteraction *interaction in interactionsToDelete) { DDLogDebug(@"Cleaning up interaction: %@", [interaction class]); - [writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { - [interaction removeWithTransaction:writeTransaction]; - }]; + [interaction removeWithTransaction:transaction]; } // Determine if there are "unread" messages in this conversation. @@ -551,11 +546,7 @@ NS_ASSUME_NONNULL_BEGIN // Preserve the timestamp of the existing "contact offers" so that // we replace it in the same position in the timeline. contactOffersTimestamp = existingContactOffers.timestamp; - - [writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { - [existingContactOffers removeWithTransaction:writeTransaction]; - }]; - + [existingContactOffers removeWithTransaction:transaction]; existingContactOffers = nil; } } @@ -565,9 +556,7 @@ NS_ASSUME_NONNULL_BEGIN self.logTag, existingContactOffers.uniqueId, existingContactOffers.timestampForSorting); - [writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { - [existingContactOffers removeWithTransaction:writeTransaction]; - }]; + [existingContactOffers removeWithTransaction:transaction]; } else if (!existingContactOffers && shouldHaveContactOffers) { NSString *recipientId = ((TSContactThread *)thread).contactIdentifier; @@ -578,9 +567,7 @@ NS_ASSUME_NONNULL_BEGIN hasAddToContactsOffer:shouldHaveAddToContactsOffer hasAddToProfileWhitelistOffer:shouldHaveAddToProfileWhitelistOffer recipientId:recipientId]; - [writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { - [offersMessage saveWithTransaction:writeTransaction]; - }]; + [offersMessage saveWithTransaction:transaction]; DDLogInfo(@"%@ Creating contact offers: %@ (%llu)", self.logTag, @@ -595,9 +582,7 @@ NS_ASSUME_NONNULL_BEGIN DDLogInfo(@"%@ Removing obsolete TSUnreadIndicatorInteraction: %@", self.logTag, existingUnreadIndicator.uniqueId); - [writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { - [existingUnreadIndicator removeWithTransaction:writeTransaction]; - }]; + [existingUnreadIndicator removeWithTransaction:transaction]; } } else { // We want the unread indicator to appear just before the first unread incoming @@ -614,9 +599,7 @@ NS_ASSUME_NONNULL_BEGIN DDLogInfo(@"%@ Removing TSUnreadIndicatorInteraction due to changed timestamp: %@", self.logTag, existingUnreadIndicator.uniqueId); - [writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { - [existingUnreadIndicator removeWithTransaction:writeTransaction]; - }]; + [existingUnreadIndicator removeWithTransaction:transaction]; } TSUnreadIndicatorInteraction *indicator = [[TSUnreadIndicatorInteraction alloc] @@ -624,9 +607,7 @@ NS_ASSUME_NONNULL_BEGIN thread:thread hasMoreUnseenMessages:result.hasMoreUnseenMessages missingUnseenSafetyNumberChangeCount:missingUnseenSafetyNumberChangeCount]; - [writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { - [indicator saveWithTransaction:writeTransaction]; - }]; + [indicator saveWithTransaction:transaction]; DDLogInfo(@"%@ Creating TSUnreadIndicatorInteraction: %@ (%llu)", self.logTag, @@ -636,14 +617,6 @@ NS_ASSUME_NONNULL_BEGIN } }]; - if (writeBlocks.count > 0) { - [editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull writeTransaction) { - for (void (^ writeBlock)(YapDatabaseReadWriteTransaction *) in writeBlocks) { - writeBlock(writeTransaction); - } - }]; - } - return result; }