Skip to content

Commit e3d1de1

Browse files
committed
Switch user stats to save sequentially
1 parent 6e043f1 commit e3d1de1

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

game_logic/complete-all-games.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,23 @@ var updateMaxGameTurn = function(mongoConnection, game) {
168168
console.log('Game turns updated successfully!');
169169
console.log('Updating all user stats...');
170170

171-
return Q.all(game.heroes.map(function(hero) {
172-
return saveUserStats(mongoConnection, hero, game.baseId);
173-
}))
171+
// Save each hero's stats for the most recent game
172+
// Loop recursively until complete, return a promise
173+
var saveStatsForNextHero = function() {
174+
var hero = heroesToSave.pop();
174175

176+
return saveUserStats(mongoConnection, hero, game.baseId)
177+
178+
.then(function() {
179+
if (heroesToSave.length > 0) {
180+
return saveAllHeroStats();
181+
}
182+
});
183+
};
184+
185+
var heroesToSave = game.heroes.slice();
186+
187+
return saveStatsForNextHero()
175188
.then(function() {
176189
console.log('All user stats updated for game #' + game.gameNumber);
177190
});

0 commit comments

Comments
 (0)