@@ -1182,8 +1182,8 @@ async function toggleStar(userid: string, pars: {metaGame: string}) {
11821182 TableName : process . env . ABSTRACT_PLAY_TABLE ,
11831183 Key : { "pk" : "METAGAMES" , "sk" : "COUNTS" } ,
11841184 ExpressionAttributeNames : { "#g" : pars . metaGame } ,
1185- ExpressionAttributeValues : { ":n" : delta } ,
1186- UpdateExpression : "add #g.stars :n" ,
1185+ ExpressionAttributeValues : { ":n" : delta , ":zero" : 0 } ,
1186+ UpdateExpression : "set #g.stars = if_not_exists(#g.stars, :zero) + :n" ,
11871187 } ) )
11881188 ) ;
11891189
@@ -2185,9 +2185,9 @@ async function newChallenge(userid: string, challenge: FullChallenge) {
21852185 const updateChallenger = ddbDocClient . send ( new UpdateCommand ( {
21862186 TableName : process . env . ABSTRACT_PLAY_TABLE ,
21872187 Key : { "pk" : "USER" , "sk" : userid } ,
2188- ExpressionAttributeValues : { ":c" : new Set ( [ challengeId ] ) } ,
2188+ ExpressionAttributeValues : { ":c" : new Set ( [ challengeId ] ) , ":empty" : new Set ( ) } ,
21892189 ExpressionAttributeNames : { "#c" : "challenges" } ,
2190- UpdateExpression : "add #c.issued :c" ,
2190+ UpdateExpression : "set #c.issued = if_not_exists(#c.issued, :empty) add :c" ,
21912191 } ) ) ;
21922192
21932193 const list : Promise < any > [ ] = [ addChallenge , updateChallenger ] ;
@@ -2197,9 +2197,9 @@ async function newChallenge(userid: string, challenge: FullChallenge) {
21972197 ddbDocClient . send ( new UpdateCommand ( {
21982198 TableName : process . env . ABSTRACT_PLAY_TABLE ,
21992199 Key : { "pk" : "USER" , "sk" : challengee . id } ,
2200- ExpressionAttributeValues : { ":c" : new Set ( [ challengeId ] ) } ,
2200+ ExpressionAttributeValues : { ":c" : new Set ( [ challengeId ] ) , ":empty" : new Set ( ) } ,
22012201 ExpressionAttributeNames : { "#c" : "challenges" } ,
2202- UpdateExpression : "add #c.received :c" ,
2202+ UpdateExpression : "set #c.received = if_not_exists(#c.received, :empty) add :c" ,
22032203 } ) )
22042204 ) ;
22052205 } )
@@ -2266,9 +2266,9 @@ async function newStandingChallenge(userid: string, challenge: FullChallenge) {
22662266 const updateChallenger = ddbDocClient . send ( new UpdateCommand ( {
22672267 TableName : process . env . ABSTRACT_PLAY_TABLE ,
22682268 Key : { "pk" : "USER" , "sk" : userid } ,
2269- ExpressionAttributeValues : { ":c" : new Set ( [ challenge . metaGame + '#' + challengeId ] ) } ,
2269+ ExpressionAttributeValues : { ":c" : new Set ( [ challenge . metaGame + '#' + challengeId ] ) , ":empty" : new Set ( ) } ,
22702270 ExpressionAttributeNames : { "#c" : "challenges" } ,
2271- UpdateExpression : "add #c.standing :c" ,
2271+ UpdateExpression : "set #c.standing = if_not_exists(#c.standing, :empty) add :c" ,
22722272 } ) ) ;
22732273
22742274 const updateStandingChallengeCnt = updateStandingChallengeCount ( challenge . metaGame , 1 ) ;
@@ -2687,8 +2687,8 @@ async function updateStandingChallengeCount(metaGame: any, diff: number) {
26872687 TableName : process . env . ABSTRACT_PLAY_TABLE ,
26882688 Key : { "pk" : "METAGAMES" , "sk" : "COUNTS" } ,
26892689 ExpressionAttributeNames : { "#g" : metaGame } ,
2690- ExpressionAttributeValues : { ":n" : diff } ,
2691- UpdateExpression : "add #g.standingchallenges :n" ,
2690+ ExpressionAttributeValues : { ":n" : diff , ":zero" : 0 } ,
2691+ UpdateExpression : "set #g.standingchallenges = if_not_exists(#g.standingchallenges, :zero) + :n" ,
26922692 } ) ) ;
26932693}
26942694
@@ -2842,9 +2842,9 @@ async function acceptChallenge(userid: string, metaGame: string, challengeId: st
28422842 const updateAccepter = ddbDocClient . send ( new UpdateCommand ( {
28432843 TableName : process . env . ABSTRACT_PLAY_TABLE ,
28442844 Key : { "pk" : "USER" , "sk" : userid } ,
2845- ExpressionAttributeValues : { ":c" : new Set ( [ standing ? challenge . metaGame + '#' + challengeId : challengeId ] ) } ,
2845+ ExpressionAttributeValues : { ":c" : new Set ( [ standing ? challenge . metaGame + '#' + challengeId : challengeId ] ) , ":empty" : new Set ( ) } ,
28462846 ExpressionAttributeNames : { "#c" : "challenges" } ,
2847- UpdateExpression : "delete #c.received :c add #c.accepted :c" ,
2847+ UpdateExpression : "delete #c.received :c set #c.accepted = if_not_exists(#c.accepted, :empty) add :c" ,
28482848 } ) ) ;
28492849
28502850 await Promise . all ( [ updateChallenge , updateAccepter ] ) ;
@@ -2884,9 +2884,9 @@ async function duplicateStandingChallenge(challenge: { [x: string]: any; metaGam
28842884 const updateChallenger = ddbDocClient . send ( new UpdateCommand ( {
28852885 TableName : process . env . ABSTRACT_PLAY_TABLE ,
28862886 Key : { "pk" : "USER" , "sk" : challenge . challenger . id } ,
2887- ExpressionAttributeValues : { ":c" : new Set ( [ challenge . metaGame + '#' + challengeId ] ) } ,
2887+ ExpressionAttributeValues : { ":c" : new Set ( [ challenge . metaGame + '#' + challengeId ] ) , ":empty" : new Set ( ) } ,
28882888 ExpressionAttributeNames : { "#c" : "challenges" } ,
2889- UpdateExpression : "add #c.standing :c" ,
2889+ UpdateExpression : "set #c.standing = if_not_exists(#c.standing, :empty) add :c" ,
28902890 } ) ) ;
28912891
28922892 return { challengeId, "work" : Promise . all ( [ addChallenge , updateStandingChallengeCnt , updateChallenger ] ) } ;
@@ -2969,14 +2969,14 @@ function addToGameLists(type: string, game: Game, now: number, keepgame: boolean
29692969 TableName : process . env . ABSTRACT_PLAY_TABLE ,
29702970 Key : { "pk" : "METAGAMES" , "sk" : "COUNTS" } ,
29712971 ExpressionAttributeNames : { "#g" : game . metaGame } ,
2972- ExpressionAttributeValues : { ":n" : 1 } ,
2973- UpdateExpression : "add #g.currentgames :n"
2972+ ExpressionAttributeValues : { ":n" : 1 , ":zero" : 0 } ,
2973+ UpdateExpression : "set #g.currentgames = if_not_exists(#g.currentgames, :zero) + :n"
29742974 } ) ) ) ;
29752975 } else {
2976- let update = "add #g.currentgames :nm" ;
2977- const eavObj : { [ k : string ] : number } = { ":nm" : - 1 } ;
2976+ let update = "set #g.currentgames = if_not_exists(#g.currentgames, :zero) + :nm" ;
2977+ const eavObj : { [ k : string ] : number } = { ":nm" : - 1 , ":zero" : 0 } ;
29782978 if ( keepgame ) {
2979- update += ", #g.completedgames :n" ;
2979+ update += ", #g.completedgames = if_not_exists(#g.completedgames, :zero) + :n" ;
29802980 eavObj [ ":n" ] = 1
29812981 }
29822982 work . push ( sendCommandWithRetry ( new UpdateCommand ( {
@@ -3026,8 +3026,8 @@ function deleteFromGameLists(type: string, game: FullGame) {
30263026 TableName : process . env . ABSTRACT_PLAY_TABLE ,
30273027 Key : { "pk" : "METAGAMES" , "sk" : "COUNTS" } ,
30283028 ExpressionAttributeNames : { "#g" : game . metaGame } ,
3029- ExpressionAttributeValues : { ":n" : - 1 } ,
3030- UpdateExpression : "add #g.currentgames :n"
3029+ ExpressionAttributeValues : { ":n" : - 1 , ":zero" : 0 } ,
3030+ UpdateExpression : "set #g.currentgames = if_not_exists(#g.currentgames, :zero) + :n"
30313031 } ) ) ) ;
30323032 }
30333033 return Promise . all ( work ) ;
@@ -3250,8 +3250,8 @@ async function submitMove(userid: string, pars: { id: string, move: string, draw
32503250 TableName : process . env . ABSTRACT_PLAY_TABLE ,
32513251 Key : { "pk" : "METAGAMES" , "sk" : "COUNTS" } ,
32523252 ExpressionAttributeNames : { "#g" : game . metaGame } ,
3253- ExpressionAttributeValues : { ":p" : new Set ( [ player . id ] ) } ,
3254- UpdateExpression : "add #g.ratings :p" ,
3253+ ExpressionAttributeValues : { ":p" : new Set ( [ player . id ] ) , ":empty" : new Set ( ) } ,
3254+ UpdateExpression : "set #g.ratings = if_not_exists(#g.ratings, :empty) add :p" ,
32553255 } ) ) ) ;
32563256 console . log ( `Scheduled update to metagame ratings counts with player ${ player . id } ` ) ;
32573257 }
@@ -3326,8 +3326,8 @@ async function tournamentUpdates(game: FullGame, players: FullUser[], timeout: n
33263326 TableName : process . env . ABSTRACT_PLAY_TABLE ,
33273327 Key : { "pk" : "TOURNAMENT" , "sk" : game . tournament } ,
33283328 ExpressionAttributeNames : { "#d" : "divisions" , "#n" : game . division ! . toString ( ) } ,
3329- ExpressionAttributeValues : { ":inc" : 1 } ,
3330- UpdateExpression : "add #d.#n.numCompleted :inc" ,
3329+ ExpressionAttributeValues : { ":inc" : 1 , ":zero" : 0 } ,
3330+ UpdateExpression : "set #d.#n.numCompleted = if_not_exists(#d.#n.numCompleted, :zero) + :inc" ,
33313331 ReturnValues : "ALL_NEW"
33323332 } ) ) ;
33333333 const tournament = tournamentData . Attributes as Tournament ;
@@ -3712,8 +3712,8 @@ async function timeloss(check: boolean, player: number, gameid: string, metaGame
37123712 TableName : process . env . ABSTRACT_PLAY_TABLE ,
37133713 Key : { "pk" : "METAGAMES" , "sk" : "COUNTS" } ,
37143714 ExpressionAttributeNames : { "#g" : game . metaGame } ,
3715- ExpressionAttributeValues : { ":p" : new Set ( [ player . id ] ) } ,
3716- UpdateExpression : "add #g.ratings :p" ,
3715+ ExpressionAttributeValues : { ":p" : new Set ( [ player . id ] ) , ":empty" : new Set ( ) } ,
3716+ UpdateExpression : "set #g.ratings = if_not_exists(#g.ratings, :empty) add :p" ,
37173717 } ) ) ) ;
37183718 }
37193719 } ) ;
0 commit comments