@@ -140,14 +140,18 @@ async function compareCurrentApiType(
140140 const operationsMap = createPairOperationsMap ( previousGroupSlug , currentGroupSlug , prevOperationsWithPrefix , currOperationsWithPrefix , apiBuilder )
141141 const operationPairs = Object . values ( operationsMap )
142142 const pairedDocs = await calculatePairedDocs ( operationPairs , pairContext )
143- const [ operationChanges , tags ] = await comparePairedDocs ( operationsMap , pairedDocs , apiBuilder , pairContext )
143+ const [ operationChanges , uniqueDiffsForDocPairs , tags ] = await comparePairedDocs ( operationsMap , pairedDocs , apiBuilder , pairContext )
144144 // Duplicates could happen in rare case when document for added/deleted operation was mapped to several documents in other version
145145 const uniqueOperationChanges = removeObjectDuplicates (
146146 operationChanges ,
147147 ( item ) => `${ item . apiType } :${ item . operationId ?? '' } :${ item . previousOperationId ?? '' } ` ,
148148 )
149149
150- const uniqueDiffs = removeObjectDuplicates ( uniqueOperationChanges . flatMap ( ( { diffs } ) => diffs ) , calculateDiffId )
150+ // We only need to additionally deduplicate diffs if there are multiple document pairs
151+ // because diffs coming from the same apiDiff call are already deduplicated in comparePairedDocs
152+ // This is performance optimization for common case when there is only one document pair
153+ const uniqueDiffs = uniqueDiffsForDocPairs . length === 1 ? Array . from ( uniqueDiffsForDocPairs [ 0 ] )
154+ : removeObjectDuplicates ( uniqueDiffsForDocPairs . flatMap ( set => Array . from ( set ) ) , calculateDiffId )
151155 const changesSummary = calculateChangeSummary ( uniqueDiffs )
152156 const numberOfImpactedOperations = calculateTotalImpactedSummary (
153157 uniqueOperationChanges . map ( ( { impactedSummary } ) => impactedSummary ) ,
0 commit comments