Revert "separate read/write db connections"

This reverts commit 3e61741060e6a7c2a9891b46cf3abd567d33aa3a.
pull/1/head
Michael Kirk 7 years ago
parent 00f8ea4ff8
commit 468f7524ef

@ -2471,8 +2471,7 @@ typedef enum : NSUInteger {
[ThreadUtil ensureDynamicInteractionsForThread:self.thread [ThreadUtil ensureDynamicInteractionsForThread:self.thread
contactsManager:self.contactsManager contactsManager:self.contactsManager
blockingManager:self.blockingManager blockingManager:self.blockingManager
uiDatabaseConnection:self.uiDatabaseConnection dbConnection:self.editingDatabaseConnection
editingDatabaseConnection:self.editingDatabaseConnection
hideUnreadMessagesIndicator:self.hasClearedUnreadMessagesIndicator hideUnreadMessagesIndicator:self.hasClearedUnreadMessagesIndicator
firstUnseenInteractionTimestamp:self.dynamicInteractions.firstUnseenInteractionTimestamp firstUnseenInteractionTimestamp:self.dynamicInteractions.firstUnseenInteractionTimestamp
maxRangeSize:maxRangeSize]; maxRangeSize:maxRangeSize];

@ -102,10 +102,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread + (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread
contactsManager:(OWSContactsManager *)contactsManager contactsManager:(OWSContactsManager *)contactsManager
blockingManager:(OWSBlockingManager *)blockingManager blockingManager:(OWSBlockingManager *)blockingManager
uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection dbConnection:(YapDatabaseConnection *)dbConnection
editingDatabaseConnection:(YapDatabaseConnection *)editingDatabaseConnection
hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator
firstUnseenInteractionTimestamp:(nullable NSNumber *)firstUnseenInteractionTimestampParameter firstUnseenInteractionTimestamp:(nullable NSNumber *)firstUnseenInteractionTimestamp
maxRangeSize:(int)maxRangeSize; maxRangeSize:(int)maxRangeSize;
+ (BOOL)shouldShowGroupProfileBannerInThread:(TSThread *)thread blockingManager:(OWSBlockingManager *)blockingManager; + (BOOL)shouldShowGroupProfileBannerInThread:(TSThread *)thread blockingManager:(OWSBlockingManager *)blockingManager;

@ -217,16 +217,14 @@ NS_ASSUME_NONNULL_BEGIN
+ (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread + (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread
contactsManager:(OWSContactsManager *)contactsManager contactsManager:(OWSContactsManager *)contactsManager
blockingManager:(OWSBlockingManager *)blockingManager blockingManager:(OWSBlockingManager *)blockingManager
uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection dbConnection:(YapDatabaseConnection *)dbConnection
editingDatabaseConnection:(YapDatabaseConnection *)editingDatabaseConnection
hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator
firstUnseenInteractionTimestamp: firstUnseenInteractionTimestamp:
(nullable NSNumber *)firstUnseenInteractionTimestampParameter (nullable NSNumber *)firstUnseenInteractionTimestampParameter
maxRangeSize:(int)maxRangeSize maxRangeSize:(int)maxRangeSize
{ {
OWSAssert(thread); OWSAssert(thread);
OWSAssert(uiDatabaseConnection); OWSAssert(dbConnection);
OWSAssert(editingDatabaseConnection);
OWSAssert(contactsManager); OWSAssert(contactsManager);
OWSAssert(blockingManager); OWSAssert(blockingManager);
OWSAssert(maxRangeSize > 0); OWSAssert(maxRangeSize > 0);
@ -249,8 +247,7 @@ NS_ASSUME_NONNULL_BEGIN
ThreadDynamicInteractions *result = [ThreadDynamicInteractions new]; ThreadDynamicInteractions *result = [ThreadDynamicInteractions new];
NSMutableArray *writeBlocks = [NSMutableArray new]; [dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
const int kMaxBlockOfferOutgoingMessageCount = 10; const int kMaxBlockOfferOutgoingMessageCount = 10;
// Find any "dynamic" interactions and safety number changes. // Find any "dynamic" interactions and safety number changes.
@ -308,9 +305,7 @@ NS_ASSUME_NONNULL_BEGIN
for (TSInteraction *interaction in interactionsToDelete) { for (TSInteraction *interaction in interactionsToDelete) {
DDLogDebug(@"Cleaning up interaction: %@", [interaction class]); DDLogDebug(@"Cleaning up interaction: %@", [interaction class]);
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { [interaction removeWithTransaction:transaction];
[interaction removeWithTransaction:writeTransaction];
}];
} }
// Determine if there are "unread" messages in this conversation. // 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 // Preserve the timestamp of the existing "contact offers" so that
// we replace it in the same position in the timeline. // we replace it in the same position in the timeline.
contactOffersTimestamp = existingContactOffers.timestamp; contactOffersTimestamp = existingContactOffers.timestamp;
[existingContactOffers removeWithTransaction:transaction];
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
[existingContactOffers removeWithTransaction:writeTransaction];
}];
existingContactOffers = nil; existingContactOffers = nil;
} }
} }
@ -565,9 +556,7 @@ NS_ASSUME_NONNULL_BEGIN
self.logTag, self.logTag,
existingContactOffers.uniqueId, existingContactOffers.uniqueId,
existingContactOffers.timestampForSorting); existingContactOffers.timestampForSorting);
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { [existingContactOffers removeWithTransaction:transaction];
[existingContactOffers removeWithTransaction:writeTransaction];
}];
} else if (!existingContactOffers && shouldHaveContactOffers) { } else if (!existingContactOffers && shouldHaveContactOffers) {
NSString *recipientId = ((TSContactThread *)thread).contactIdentifier; NSString *recipientId = ((TSContactThread *)thread).contactIdentifier;
@ -578,9 +567,7 @@ NS_ASSUME_NONNULL_BEGIN
hasAddToContactsOffer:shouldHaveAddToContactsOffer hasAddToContactsOffer:shouldHaveAddToContactsOffer
hasAddToProfileWhitelistOffer:shouldHaveAddToProfileWhitelistOffer hasAddToProfileWhitelistOffer:shouldHaveAddToProfileWhitelistOffer
recipientId:recipientId]; recipientId:recipientId];
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { [offersMessage saveWithTransaction:transaction];
[offersMessage saveWithTransaction:writeTransaction];
}];
DDLogInfo(@"%@ Creating contact offers: %@ (%llu)", DDLogInfo(@"%@ Creating contact offers: %@ (%llu)",
self.logTag, self.logTag,
@ -595,9 +582,7 @@ NS_ASSUME_NONNULL_BEGIN
DDLogInfo(@"%@ Removing obsolete TSUnreadIndicatorInteraction: %@", DDLogInfo(@"%@ Removing obsolete TSUnreadIndicatorInteraction: %@",
self.logTag, self.logTag,
existingUnreadIndicator.uniqueId); existingUnreadIndicator.uniqueId);
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { [existingUnreadIndicator removeWithTransaction:transaction];
[existingUnreadIndicator removeWithTransaction:writeTransaction];
}];
} }
} else { } else {
// We want the unread indicator to appear just before the first unread incoming // 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: %@", DDLogInfo(@"%@ Removing TSUnreadIndicatorInteraction due to changed timestamp: %@",
self.logTag, self.logTag,
existingUnreadIndicator.uniqueId); existingUnreadIndicator.uniqueId);
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { [existingUnreadIndicator removeWithTransaction:transaction];
[existingUnreadIndicator removeWithTransaction:writeTransaction];
}];
} }
TSUnreadIndicatorInteraction *indicator = [[TSUnreadIndicatorInteraction alloc] TSUnreadIndicatorInteraction *indicator = [[TSUnreadIndicatorInteraction alloc]
@ -624,9 +607,7 @@ NS_ASSUME_NONNULL_BEGIN
thread:thread thread:thread
hasMoreUnseenMessages:result.hasMoreUnseenMessages hasMoreUnseenMessages:result.hasMoreUnseenMessages
missingUnseenSafetyNumberChangeCount:missingUnseenSafetyNumberChangeCount]; missingUnseenSafetyNumberChangeCount:missingUnseenSafetyNumberChangeCount];
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) { [indicator saveWithTransaction:transaction];
[indicator saveWithTransaction:writeTransaction];
}];
DDLogInfo(@"%@ Creating TSUnreadIndicatorInteraction: %@ (%llu)", DDLogInfo(@"%@ Creating TSUnreadIndicatorInteraction: %@ (%llu)",
self.logTag, 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; return result;
} }

Loading…
Cancel
Save