diff --git a/Source/CBL_SQLiteStorage.m b/Source/CBL_SQLiteStorage.m index bbf811212..7ed95feb9 100644 --- a/Source/CBL_SQLiteStorage.m +++ b/Source/CBL_SQLiteStorage.m @@ -1625,7 +1625,7 @@ - (CBLStatus) forceInsert: (CBL_Revision*)inRev __block BOOL inConflict = NO; CBLStatus status = [self inTransaction: ^CBLStatus { // First look up the document's row-id and all locally-known revisions of it: - CBL_RevisionList* localRevs = nil; + NSMutableDictionary* localRevs = nil; NSString* oldWinningRevID = nil; BOOL oldWinnerWasDeletion = NO; BOOL isNewDoc = (history.count == 1); @@ -1633,11 +1633,14 @@ - (CBLStatus) forceInsert: (CBL_Revision*)inRev if (docNumericID <= 0) return self.lastDbError; if (!isNewDoc) { - localRevs = [self getAllRevisionsOfDocumentID: docID - numericID: docNumericID - onlyCurrent: NO]; - if (!localRevs) + CBL_RevisionList* localRevsList = [self getAllRevisionsOfDocumentID: docID + numericID: docNumericID + onlyCurrent: NO]; + if (!localRevsList) return self.lastDbError; + localRevs = [[NSMutableDictionary alloc] initWithCapacity: localRevsList.count]; + for (CBL_Revision* rev in localRevsList) + localRevs[rev.revID] = rev; // Look up which rev is the winner, before this insertion CBLStatus tempStatus; @@ -1653,7 +1656,7 @@ - (CBLStatus) forceInsert: (CBL_Revision*)inRev if (validationBlock) { CBL_Revision* oldRev = nil; for (NSUInteger i = 1; i=0; --i) { NSString* revID = history[i]; - CBL_Revision* localRev = [localRevs revWithDocID: docID revID: revID]; + CBL_Revision* localRev = localRevs[revID]; if (localRev) { // This revision is known locally. Remember its sequence as the parent of the next one: sequence = localRev.sequence;