至少同时执行 >10 个请求,此代码插入 4 条相同的记录,但只能插入 1 条。
用户只能开始 1 个活动游戏。(在活跃的游戏领域finished = false
)
console.log('performing request');
const activeGame = await db.Game.findOne({ uid, finished: false });
if (activeGame !== null) {
console.log('errored');
return { error: 'Finish previous game.' };
} else {
console.log('inserted');
const game = new db.Game({
uid,
moves: new Array(5*5).fill(0)
});
game.save();
return game;
}
同时记录 10 个请求:
performing request
inserted
performing request
performing request
inserted
performing request
inserted
inserted
performing request
errored
performing request
errored
performing request
errored
performing request
errored
performing request
performing request
errored
errored
交易对我没有帮助。