From 9017c16e7efa88bf0415f7e1c70d3f4ac621b042 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 12 Dec 2018 15:24:36 -0500 Subject: [PATCH] Sort interactions in CVM. --- .../ConversationView/ConversationViewModel.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m index 308039342..3586f93ed 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewModel.m @@ -538,6 +538,7 @@ static const int kYapDatabaseRangeMinLength = 0; [updatedNeighborItemSet addObject:viewItem.itemId]; } } else { + OWSLogError(@"Update is missing view item"); hasMalformedRowChange = YES; } } else if (rowChange.indexPath && rowChange.originalIndex < self.viewItems.count) { @@ -545,6 +546,7 @@ static const int kYapDatabaseRangeMinLength = 0; // setCellDrawingDependencyOffsets. OWSAssertDebug(rowChange.changes == YapDatabaseViewChangedDependency); } else { + OWSFailDebug(@"Update is missing collection key"); hasMalformedRowChange = YES; } break; @@ -555,6 +557,7 @@ static const int kYapDatabaseRangeMinLength = 0; if (collectionKey.key) { [self.viewItemCache removeObjectForKey:collectionKey.key]; } else { + OWSFailDebug(@"Delete is missing collection key"); hasMalformedRowChange = YES; } break; @@ -934,6 +937,12 @@ static const int kYapDatabaseRangeMinLength = 0; } }]; + // This will usually be redundant, but this will resolve one of the symptoms + // of the "corrupt YDB view" issue caused by multi-process writes. + [viewItems sortUsingComparator:^NSComparisonResult(id left, id right) { + return [left.interaction compareForSorting:right.interaction]; + }]; + // Flag to ensure that we only increment once per launch. if (hasError) { OWSLogWarn(@"incrementing version of: %@", TSMessageDatabaseViewExtensionName);