File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,13 @@ class UserStatsService {
1818 return null ;
1919 }
2020
21+ // Use provided newElo if available (for ranked duels where setElo may not have completed yet)
22+ // This avoids race condition where we read stale ELO from DB before setElo writes complete
23+ const eloToRecord = gameData . newElo ?? user . elo ?? 1000 ;
24+
2125 // Get current rankings
2226 const xpRank = await this . calculateXPRank ( user . totalXp ) ;
23- const eloRankResult = await this . calculateELORank ( user . elo || 1000 ) ;
27+ const eloRankResult = await this . calculateELORank ( eloToRecord ) ;
2428 const eloRank = typeof eloRankResult === 'object' ? eloRankResult . rank : eloRankResult ;
2529
2630 // Record the stats snapshot
@@ -29,7 +33,7 @@ class UserStatsService {
2933 timestamp : new Date ( ) ,
3034 totalXp : user . totalXp || 0 ,
3135 xpRank : xpRank ,
32- elo : user . elo || 1000 ,
36+ elo : eloToRecord ,
3337 eloRank : eloRank ,
3438 triggerEvent : gameData ?. triggerEvent || 'game_completed' ,
3539 gameId : gameId
Original file line number Diff line number Diff line change @@ -188,7 +188,9 @@ export default function UserProfilePage() {
188188 < div className = "back-button-container" >
189189 < button
190190 className = "back-to-wg-button"
191- onClick = { ( ) => router . push ( '/' ) }
191+ // onClick={() => router.push('/')}
192+ // use window.location.href
193+ onClick = { ( ) => window . location . href = '/' }
192194 >
193195 ← Go to WorldGuessr
194196 </ button >
Original file line number Diff line number Diff line change @@ -1191,7 +1191,8 @@ export default class Game {
11911191 opponent : this . accountIds . p2 ,
11921192 eloChange : p1NewElo ? ( p1NewElo - p1OldElo ) : 0 ,
11931193 finalScore : player1Data ?. score || 0 ,
1194- duration : this . endTime - this . startTime
1194+ duration : this . endTime - this . startTime ,
1195+ newElo : p1NewElo // Pass new ELO directly to avoid race condition with setElo
11951196 }
11961197 ) ;
11971198 console . log ( `Created userstats for player 1: ${ this . accountIds . p1 } ` ) ;
@@ -1208,7 +1209,8 @@ export default class Game {
12081209 opponent : this . accountIds . p1 ,
12091210 eloChange : p2NewElo ? ( p2NewElo - p2OldElo ) : 0 ,
12101211 finalScore : player2Data ?. score || 0 ,
1211- duration : this . endTime - this . startTime
1212+ duration : this . endTime - this . startTime ,
1213+ newElo : p2NewElo // Pass new ELO directly to avoid race condition with setElo
12121214 }
12131215 ) ;
12141216 console . log ( `Created userstats for player 2: ${ this . accountIds . p2 } ` ) ;
You can’t perform that action at this time.
0 commit comments