@@ -124,7 +124,7 @@ public async Task<List<Word>> Create(List<Word> words)
124124 OtelService . StartActivityWithTag ( otelTagName , "creating words in WordsCollection and Frontier" ) ;
125125
126126 return words . Count == 0
127- ? [ ]
127+ ? words
128128 : await _dbContext . ExecuteInTransaction ( async s => await CreateWithSession ( s , words ) ) ;
129129 }
130130
@@ -335,15 +335,13 @@ public async Task<bool> RestoreFrontier(string projectId, string wordId)
335335 /// <param name="modifyDeletedWord">
336336 /// Action applied to words deleted from Frontier before inserting into WordsCollection.
337337 /// </param>
338- /// <returns>
339- /// The replacement words when successful, an empty list if no work is needed, or null if replacement fails.
340- /// </returns>
341- public async Task < List < Word > ? > ReplaceFrontier ( string projectId , List < Word > newWords ,
338+ /// <returns>The replacement words when successful, an empty list if no work is needed.</returns>
339+ public async Task < List < Word > > ReplaceFrontier ( string projectId , List < Word > newWords ,
342340 List < string > idsToDelete , Action < Word , Word ? > modifyUpdatedWord , Action < Word > modifyDeletedWord )
343341 {
344342 return ( newWords . Count == 0 && idsToDelete . Count == 0 )
345- ? [ ]
346- : await _dbContext . ExecuteInTransactionAllowNull ( async s => await ReplaceFrontierWithSession (
343+ ? newWords
344+ : await _dbContext . ExecuteInTransaction ( async s => await ReplaceFrontierWithSession (
347345 s , projectId , newWords , idsToDelete , modifyUpdatedWord , modifyDeletedWord ) ) ;
348346 }
349347
@@ -469,8 +467,9 @@ private async Task<List<Word>> CreateWithSession(IClientSessionHandle session, L
469467 /// <param name="modifyDeletedWord">Action applied on deleted Frontier words added to WordsCollection.</param>
470468 /// <returns>True when all requested restores succeed; otherwise false.</returns>
471469 /// <exception cref="ArgumentException">Thrown when restore and delete id sets are not disjoint.</exception>
472- private async Task < bool > RevertReplaceFrontierWithSession ( IClientSessionHandle session , string projectId ,
473- IEnumerable < string > idsToRestore , IEnumerable < string > idsToDelete , Action < Word > modifyDeletedWord )
470+ private async Task < bool > RevertReplaceFrontierWithSession ( IClientSessionHandle session ,
471+ string projectId , IEnumerable < string > idsToRestore , IEnumerable < string > idsToDelete ,
472+ Action < Word > modifyDeletedWord )
474473 {
475474 var restoreSet = idsToRestore . ToHashSet ( ) ; // Remove duplicates
476475 if ( restoreSet . Intersect ( idsToDelete ) . Any ( ) )
@@ -498,9 +497,9 @@ private async Task<bool> RevertReplaceFrontierWithSession(IClientSessionHandle s
498497 /// <param name="oldWordIds">Ids of Frontier words that will be replaced or deleted.</param>
499498 /// <param name="modifyUpdatedWord">Action applied when building each replacement word.</param>
500499 /// <param name="modifyDeletedWord">Action applied on deleted Frontier words added to WordsCollection.</param>
501- /// <returns>The replacement words, or null if a required update fails .</returns>
500+ /// <returns>The replaced words.</returns>
502501 /// <exception cref="ArgumentException">Thrown when a replacement word has a different project id.</exception>
503- private async Task < List < Word > ? > ReplaceFrontierWithSession ( IClientSessionHandle session ,
502+ private async Task < List < Word > > ReplaceFrontierWithSession ( IClientSessionHandle session ,
504503 string projectId , List < Word > newWords , IEnumerable < string > oldWordIds ,
505504 Action < Word , Word ? > modifyUpdatedWord , Action < Word > modifyDeletedWord )
506505 {
@@ -509,15 +508,14 @@ private async Task<bool> RevertReplaceFrontierWithSession(IClientSessionHandle s
509508 throw new ArgumentException ( "All new words must have the specified projectId" ) ;
510509 }
511510
512- var oldIdSet = oldWordIds . ToHashSet ( ) ; // Remove duplicates
511+ var oldIdSet = oldWordIds . ToHashSet ( ) ; // Remove duplicates and allow easy removal for each update.
513512
514513 foreach ( var word in newWords )
515514 {
515+ // Remove the id from the old ids (if present) before the word is updated and given a new id.
516516 oldIdSet . Remove ( word . Id ) ;
517- if ( await UpdateFrontierWithSession ( session , word , createIfNotFound : true , modifyUpdatedWord ) is null )
518- {
519- return null ;
520- }
517+ // `createIfNotFound: true` so the word is created even if the id isn't in the Frontier.
518+ await UpdateFrontierWithSession ( session , word , createIfNotFound : true , modifyUpdatedWord ) ;
521519 }
522520
523521 // Delete any remaining old words that weren't updated with a new word
0 commit comments