From f4b8dc06d27316e53b4e7ebd2cc117a2db78bbf4 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 21 Aug 2019 11:53:03 -0300 Subject: [PATCH] Remove YDB usage. --- .../src/Messages/Interactions/TSInteraction.m | 57 +++++-------------- .../src/Messages/Interactions/TSMessage.m | 54 +++++------------- 2 files changed, 27 insertions(+), 84 deletions(-) diff --git a/SignalServiceKit/src/Messages/Interactions/TSInteraction.m b/SignalServiceKit/src/Messages/Interactions/TSInteraction.m index a9d5a1bd5a..723572e734 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSInteraction.m +++ b/SignalServiceKit/src/Messages/Interactions/TSInteraction.m @@ -263,45 +263,28 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) (unsigned long)self.timestamp]; } -// GRDB TODO: Remove. -- (void)ydb_saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction -{ - [self ensureIdsWithTransaction:transaction]; - - [super ydb_saveWithTransaction:transaction]; - - [self updateLastMessageWithTransaction:transaction.asAnyWrite]; -} - -// GRDB TODO: Remove. -- (void)ydb_removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction -{ - [super ydb_removeWithTransaction:transaction]; - - [self touchThreadWithTransaction:transaction.asAnyWrite]; -} - #pragma mark - Any Transaction Hooks - (void)anyWillInsertWithTransaction:(SDSAnyWriteTransaction *)transaction { - // GRDB TODO: Remove this condition once we migrate interaction writes to use - // any transactions. We just don't want to do this work twice. - if (transaction.transitional_yapWriteTransaction != nil) { - [self ensureIdsWithTransaction:transaction.transitional_yapWriteTransaction]; - } - [super anyWillInsertWithTransaction:transaction]; + + [self ensureIdsWithTransaction:transaction]; } -- (void)ensureIdsWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)ensureIdsWithTransaction:(SDSAnyWriteTransaction *)transaction { + if (transaction.transitional_yapWriteTransaction == nil) { + return; + } if (self.uniqueId.length < 1) { OWSFailDebug(@"Missing uniqueId."); + return; } if (self.sortId == 0) { - self.sortId = [SSKIncrementingIdFinder nextIdWithKey:[TSInteraction collection] transaction:transaction]; + self.sortId = [SSKIncrementingIdFinder nextIdWithKey:[TSInteraction collection] + transaction:transaction.transitional_yapWriteTransaction]; } } @@ -309,26 +292,18 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) { [super anyDidInsertWithTransaction:transaction]; - // GRDB TODO: Remove this condition once we migrate interaction writes to use - // any transactions. We just don't want to do this work twice. - if (transaction.transitional_yapWriteTransaction == nil) { - [self updateLastMessageWithTransaction:transaction]; + [self updateLastMessageWithTransaction:transaction]; - [self touchThreadWithTransaction:transaction]; - } + [self touchThreadWithTransaction:transaction]; } - (void)anyDidUpdateWithTransaction:(SDSAnyWriteTransaction *)transaction { [super anyDidUpdateWithTransaction:transaction]; - // GRDB TODO: Remove this condition once we migrate interaction writes to use - // any transactions. We just don't want to do this work twice. - if (transaction.transitional_yapWriteTransaction == nil) { - [self updateLastMessageWithTransaction:transaction]; + [self updateLastMessageWithTransaction:transaction]; - [self touchThreadWithTransaction:transaction]; - } + [self touchThreadWithTransaction:transaction]; } - (void)touchThreadWithTransaction:(SDSAnyWriteTransaction *)transaction @@ -347,11 +322,7 @@ NSString *NSStringFromOWSInteractionType(OWSInteractionType value) { [super anyDidRemoveWithTransaction:transaction]; - // GRDB TODO: Remove this condition once we migrate interaction writes to use - // any transactions. We just don't want to do this work twice. - if (transaction.transitional_yapWriteTransaction == nil) { - [self touchThreadWithTransaction:transaction]; - } + [self touchThreadWithTransaction:transaction]; } #pragma mark - diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.m b/SignalServiceKit/src/Messages/Interactions/TSMessage.m index dc9d00da16..a679f30336 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.m @@ -484,57 +484,33 @@ static const NSUInteger OWSMessageSchemaVersion = 4; } } -// GRDB TODO: Convert to Any. -- (void)ydb_saveWithTransaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)anyWillInsertWithTransaction:(SDSAnyWriteTransaction *)transaction { + [super anyWillInsertWithTransaction:transaction]; + // StickerManager does reference counting of "known" sticker packs. if (self.messageSticker != nil) { BOOL willInsert = (self.uniqueId.length < 1 - || nil == [TSMessage anyFetchWithUniqueId:self.uniqueId transaction:transaction.asAnyWrite]); + || nil == [TSMessage anyFetchWithUniqueId:self.uniqueId transaction:transaction]); if (willInsert) { - [StickerManager addKnownStickerInfo:self.messageSticker.info transaction:transaction.asAnyWrite]; + [StickerManager addKnownStickerInfo:self.messageSticker.info transaction:transaction]; } } - - [super ydb_saveWithTransaction:transaction]; -} - -// GRDB TODO: Convert to Any. -- (void)ydb_removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction -{ - // StickerManager does reference counting of "known" sticker packs. - if (self.messageSticker != nil) { - BOOL willDelete = (self.uniqueId.length > 0 - && nil != [TSMessage anyFetchWithUniqueId:self.uniqueId transaction:transaction.asAnyWrite]); - - // StickerManager does reference counting of "known" sticker packs. - if (willDelete) { - [StickerManager removeKnownStickerInfo:self.messageSticker.info transaction:transaction.asAnyWrite]; - } - } - - [super ydb_removeWithTransaction:transaction]; - - [self removeAllAttachmentsWithTransaction:transaction.asAnyWrite]; } - (void)anyWillRemoveWithTransaction:(SDSAnyWriteTransaction *)transaction { [super anyWillRemoveWithTransaction:transaction]; - // GRDB TODO: Remove this condition once we migrate interaction writes to use - // any transactions. We just don't want to do this work twice. - if (transaction.transitional_yapWriteTransaction == nil) { - // StickerManager does reference counting of "known" sticker packs. - if (self.messageSticker != nil) { - BOOL willDelete = (self.uniqueId.length > 0 - && nil != [TSMessage anyFetchWithUniqueId:self.uniqueId transaction:transaction]); + // StickerManager does reference counting of "known" sticker packs. + if (self.messageSticker != nil) { + BOOL willDelete = (self.uniqueId.length > 0 + && nil != [TSMessage anyFetchWithUniqueId:self.uniqueId transaction:transaction]); - // StickerManager does reference counting of "known" sticker packs. - if (willDelete) { - [StickerManager removeKnownStickerInfo:self.messageSticker.info transaction:transaction]; - } + // StickerManager does reference counting of "known" sticker packs. + if (willDelete) { + [StickerManager removeKnownStickerInfo:self.messageSticker.info transaction:transaction]; } } } @@ -543,11 +519,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4; { [super anyDidRemoveWithTransaction:transaction]; - // GRDB TODO: Remove this condition once we migrate interaction writes to use - // any transactions. We just don't want to do this work twice. - if (transaction.transitional_yapWriteTransaction == nil) { - [self removeAllAttachmentsWithTransaction:transaction]; - } + [self removeAllAttachmentsWithTransaction:transaction]; } - (void)removeAllAttachmentsWithTransaction:(SDSAnyWriteTransaction *)transaction