@@ -4414,20 +4414,25 @@ async function saveExploration(userid: string, pars: { public: boolean, game: st
44144414 // If we need to update the commented flag for a completed game
44154415 if ( pars . updateCommentedFlag !== undefined && pars . public && pars . gameEnded !== undefined ) {
44164416 // Update the commented flag in COMPLETEDGAMES
4417- await ddbDocClient . send ( new UpdateCommand ( {
4418- TableName : process . env . ABSTRACT_PLAY_TABLE ,
4419- Key : {
4420- "pk" : "COMPLETEDGAMES#" + pars . metaGame ,
4421- "sk" : pars . gameEnded + "#" + pars . game
4422- } ,
4423- ExpressionAttributeValues : { ":c" : pars . updateCommentedFlag } ,
4424- UpdateExpression : "set commented = :c" ,
4425- } ) ) ;
4426-
4427- console . log ( `Updated commented flag for completed game ${ pars . game } to ${ pars . updateCommentedFlag } ` ) ;
4417+ try {
4418+ await ddbDocClient . send ( new UpdateCommand ( {
4419+ TableName : process . env . ABSTRACT_PLAY_TABLE ,
4420+ Key : {
4421+ "pk" : "COMPLETEDGAMES#" + pars . metaGame ,
4422+ "sk" : pars . gameEnded + "#" + pars . game
4423+ } ,
4424+ ExpressionAttributeValues : { ":c" : pars . updateCommentedFlag } ,
4425+ UpdateExpression : "set commented = :c" ,
4426+ ConditionExpression : "attribute_exists(pk) AND attribute_exists(sk)"
4427+ } ) ) ;
4428+ console . log ( `Updated commented flag for completed game ${ pars . game } to ${ pars . updateCommentedFlag } ` ) ;
4429+ } catch ( error ) {
4430+ console . log ( `Failed to update commented flag for completed game ${ pars . game } :` , error ) ;
4431+ // Don't fail the whole operation just because of the flag update
4432+ }
44284433 }
44294434
4430- // If we need to update lastChat and seen for all players (completed games, at most once every 10 minutes )
4435+ // If we need to update lastChat and seen for all players (completed games only )
44314436 if ( pars . updateLastChat && pars . public && pars . players ) {
44324437 await updateLastChatForPlayers (
44334438 pars . game ,
@@ -7670,6 +7675,7 @@ async function updateCommented(userId: string, pars: {id: string; metaGame: stri
76707675 } ,
76717676 ExpressionAttributeValues : { ":c" : pars . commented } ,
76727677 UpdateExpression : "set commented = :c" ,
7678+ ConditionExpression : "attribute_exists(pk) AND attribute_exists(sk)"
76737679 } ) ) ;
76747680 console . log ( `Successfully updated commented flag in COMPLETEDGAMES for game ${ pars . id } to ${ pars . commented } ` ) ;
76757681 } else if ( pars . cbit === 0 ) {
@@ -7682,6 +7688,7 @@ async function updateCommented(userId: string, pars: {id: string; metaGame: stri
76827688 } ,
76837689 ExpressionAttributeValues : { ":c" : pars . commented } ,
76847690 UpdateExpression : "set commented = :c" ,
7691+ ConditionExpression : "attribute_exists(pk) AND attribute_exists(sk)"
76857692 } ) ) ;
76867693 console . log ( `Successfully updated commented flag in GAME for game ${ pars . id } to ${ pars . commented } ` ) ;
76877694 }
0 commit comments