Revert "separate read/write db connections"

This reverts commit 3e61741060e6a7c2a9891b46cf3abd567d33aa3a.
This commit is contained in:
Michael Kirk 2018-06-01 09:57:50 -04:00
parent 00f8ea4ff8
commit 468f7524ef
3 changed files with 13 additions and 42 deletions

View file

@ -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];

View file

@ -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;

View file

@ -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;
}