|
@@ -2,7 +2,7 @@ import bancho from './bancho.js';
|
|
|
import db from './database.js';
|
|
|
import Config from './util/config.js';
|
|
|
import {get_user_by_id} from './user.js';
|
|
|
-import {gen_url} from './util/helpers.js';
|
|
|
+import {capture_sentry_exception, gen_url} from './util/helpers.js';
|
|
|
import {get_division_from_elo, get_rankup_progress, update_the_one} from './elo_cache.js';
|
|
|
|
|
|
|
|
@@ -170,10 +170,14 @@ async function save_game_and_update_rating(lobby, game) {
|
|
|
'The One',
|
|
|
];
|
|
|
|
|
|
+ // Ensure users exist
|
|
|
+ for (const score of game.scores) {
|
|
|
+ score.player = await get_user_by_id(score.user_id);
|
|
|
+ }
|
|
|
+
|
|
|
const rank_changes = [];
|
|
|
for (const score of game.scores) {
|
|
|
- const player = await get_user_by_id(score.user_id);
|
|
|
- await update_the_one(score.user_id, score.rating.elo, game.mode_int);
|
|
|
+ const player = score.player;
|
|
|
if (player.ratings[game.mode_int].s3_scores < Config.games_needed_for_rank) continue;
|
|
|
|
|
|
const old_rank_text = player.ratings[game.mode_int].division;
|
|
@@ -186,6 +190,16 @@ async function save_game_and_update_rating(lobby, game) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Update "The One"
|
|
|
+ for (const score of game.scores) {
|
|
|
+ try {
|
|
|
+ await update_the_one(score.user_id, score.rating.elo, game.mode_int);
|
|
|
+ } catch (err) {
|
|
|
+ console.error('Error while updating the one', err);
|
|
|
+ capture_sentry_exception(err);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (rank_changes.length > 0) {
|
|
|
// Max 8 rank updates per message - or else it starts getting truncated
|
|
|
const MAX_UPDATES_PER_MSG = 6;
|