mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
separate read/write db connections
// FREEBIE
This commit is contained in:
parent
d9172cccb9
commit
ddd39fcd3d
3 changed files with 42 additions and 13 deletions
|
@ -2466,7 +2466,8 @@ typedef enum : NSUInteger {
|
|||
[ThreadUtil ensureDynamicInteractionsForThread:self.thread
|
||||
contactsManager:self.contactsManager
|
||||
blockingManager:self.blockingManager
|
||||
dbConnection:self.editingDatabaseConnection
|
||||
uiDatabaseConnection:self.uiDatabaseConnection
|
||||
editingDatabaseConnection:self.editingDatabaseConnection
|
||||
hideUnreadMessagesIndicator:self.hasClearedUnreadMessagesIndicator
|
||||
firstUnseenInteractionTimestamp:self.dynamicInteractions.firstUnseenInteractionTimestamp
|
||||
maxRangeSize:maxRangeSize];
|
||||
|
|
|
@ -102,9 +102,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread
|
||||
contactsManager:(OWSContactsManager *)contactsManager
|
||||
blockingManager:(OWSBlockingManager *)blockingManager
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection
|
||||
editingDatabaseConnection:(YapDatabaseConnection *)editingDatabaseConnection
|
||||
hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator
|
||||
firstUnseenInteractionTimestamp:(nullable NSNumber *)firstUnseenInteractionTimestamp
|
||||
firstUnseenInteractionTimestamp:(nullable NSNumber *)firstUnseenInteractionTimestampParameter
|
||||
maxRangeSize:(int)maxRangeSize;
|
||||
|
||||
+ (BOOL)shouldShowGroupProfileBannerInThread:(TSThread *)thread blockingManager:(OWSBlockingManager *)blockingManager;
|
||||
|
|
|
@ -217,14 +217,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (ThreadDynamicInteractions *)ensureDynamicInteractionsForThread:(TSThread *)thread
|
||||
contactsManager:(OWSContactsManager *)contactsManager
|
||||
blockingManager:(OWSBlockingManager *)blockingManager
|
||||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection
|
||||
editingDatabaseConnection:(YapDatabaseConnection *)editingDatabaseConnection
|
||||
hideUnreadMessagesIndicator:(BOOL)hideUnreadMessagesIndicator
|
||||
firstUnseenInteractionTimestamp:
|
||||
(nullable NSNumber *)firstUnseenInteractionTimestampParameter
|
||||
maxRangeSize:(int)maxRangeSize
|
||||
{
|
||||
OWSAssert(thread);
|
||||
OWSAssert(dbConnection);
|
||||
OWSAssert(uiDatabaseConnection);
|
||||
OWSAssert(editingDatabaseConnection);
|
||||
OWSAssert(contactsManager);
|
||||
OWSAssert(blockingManager);
|
||||
OWSAssert(maxRangeSize > 0);
|
||||
|
@ -247,7 +249,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
ThreadDynamicInteractions *result = [ThreadDynamicInteractions new];
|
||||
|
||||
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSMutableArray *writeBlocks = [NSMutableArray new];
|
||||
[uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
const int kMaxBlockOfferOutgoingMessageCount = 10;
|
||||
|
||||
// Find any "dynamic" interactions and safety number changes.
|
||||
|
@ -305,7 +308,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
for (TSInteraction *interaction in interactionsToDelete) {
|
||||
DDLogDebug(@"Cleaning up interaction: %@", [interaction class]);
|
||||
[interaction removeWithTransaction:transaction];
|
||||
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
||||
[interaction removeWithTransaction:writeTransaction];
|
||||
}];
|
||||
}
|
||||
|
||||
// Determine if there are "unread" messages in this conversation.
|
||||
|
@ -546,7 +551,11 @@ 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;
|
||||
[existingContactOffers removeWithTransaction:transaction];
|
||||
|
||||
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
||||
[existingContactOffers removeWithTransaction:writeTransaction];
|
||||
}];
|
||||
|
||||
existingContactOffers = nil;
|
||||
}
|
||||
}
|
||||
|
@ -556,7 +565,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
self.logTag,
|
||||
existingContactOffers.uniqueId,
|
||||
existingContactOffers.timestampForSorting);
|
||||
[existingContactOffers removeWithTransaction:transaction];
|
||||
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
||||
[existingContactOffers removeWithTransaction:writeTransaction];
|
||||
}];
|
||||
} else if (!existingContactOffers && shouldHaveContactOffers) {
|
||||
NSString *recipientId = ((TSContactThread *)thread).contactIdentifier;
|
||||
|
||||
|
@ -567,7 +578,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
hasAddToContactsOffer:shouldHaveAddToContactsOffer
|
||||
hasAddToProfileWhitelistOffer:shouldHaveAddToProfileWhitelistOffer
|
||||
recipientId:recipientId];
|
||||
[offersMessage saveWithTransaction:transaction];
|
||||
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
||||
[offersMessage saveWithTransaction:writeTransaction];
|
||||
}];
|
||||
|
||||
DDLogInfo(@"%@ Creating contact offers: %@ (%llu)",
|
||||
self.logTag,
|
||||
|
@ -582,7 +595,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
DDLogInfo(@"%@ Removing obsolete TSUnreadIndicatorInteraction: %@",
|
||||
self.logTag,
|
||||
existingUnreadIndicator.uniqueId);
|
||||
[existingUnreadIndicator removeWithTransaction:transaction];
|
||||
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
||||
[existingUnreadIndicator removeWithTransaction:writeTransaction];
|
||||
}];
|
||||
}
|
||||
} else {
|
||||
// We want the unread indicator to appear just before the first unread incoming
|
||||
|
@ -599,7 +614,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
DDLogInfo(@"%@ Removing TSUnreadIndicatorInteraction due to changed timestamp: %@",
|
||||
self.logTag,
|
||||
existingUnreadIndicator.uniqueId);
|
||||
[existingUnreadIndicator removeWithTransaction:transaction];
|
||||
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
||||
[existingUnreadIndicator removeWithTransaction:writeTransaction];
|
||||
}];
|
||||
}
|
||||
|
||||
TSUnreadIndicatorInteraction *indicator = [[TSUnreadIndicatorInteraction alloc]
|
||||
|
@ -607,7 +624,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
thread:thread
|
||||
hasMoreUnseenMessages:result.hasMoreUnseenMessages
|
||||
missingUnseenSafetyNumberChangeCount:missingUnseenSafetyNumberChangeCount];
|
||||
[indicator saveWithTransaction:transaction];
|
||||
[writeBlocks addObject:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
||||
[indicator saveWithTransaction:writeTransaction];
|
||||
}];
|
||||
|
||||
DDLogInfo(@"%@ Creating TSUnreadIndicatorInteraction: %@ (%llu)",
|
||||
self.logTag,
|
||||
|
@ -617,6 +636,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
}];
|
||||
|
||||
if (writeBlocks.count > 0) {
|
||||
[editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull writeTransaction) {
|
||||
for (void (^ writeBlock)(YapDatabaseReadWriteTransaction *) in writeBlocks) {
|
||||
writeBlock(writeTransaction);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue