Browse Source

Fix NOI contest update score not locked

pull/6/head
Menci 7 years ago
parent
commit
89296d3fa2
  1. 7
      models/contest.js
  2. 5
      models/contest_player.js

7
models/contest.js

@ -123,9 +123,8 @@ class Contest extends Model {
let problems = await this.getProblems(); let problems = await this.getProblems();
if (!problems.includes(judge_state.problem_id)) throw new ErrorMessage('当前比赛中无此题目。'); if (!problems.includes(judge_state.problem_id)) throw new ErrorMessage('当前比赛中无此题目。');
let player; await syzoj.utils.lock(['Contest::newSubmission', judge_state.user_id], async () => {
await syzoj.utils.lock(['Contest::newSubmission', 'create_player', judge_state.user_id], async () => { let player = await ContestPlayer.findInContest({
player = await ContestPlayer.findInContest({
contest_id: this.id, contest_id: this.id,
user_id: judge_state.user_id user_id: judge_state.user_id
}); });
@ -136,7 +135,6 @@ class Contest extends Model {
user_id: judge_state.user_id user_id: judge_state.user_id
}); });
} }
});
await player.updateScore(judge_state); await player.updateScore(judge_state);
await player.save(); await player.save();
@ -144,6 +142,7 @@ class Contest extends Model {
await this.loadRelationships(); await this.loadRelationships();
await this.ranklist.updatePlayer(this, player); await this.ranklist.updatePlayer(this, player);
await this.ranklist.save(); await this.ranklist.save();
});
} }
async isRunning(now) { async isRunning(now) {

5
models/contest_player.js

@ -69,7 +69,6 @@ class ContestPlayer extends Model {
} }
async updateScore(judge_state) { async updateScore(judge_state) {
await syzoj.utils.lock(['ContestPlayer::updateScore', this.id], async () => {
await this.loadRelationships(); await this.loadRelationships();
if (this.contest.type === 'ioi') { if (this.contest.type === 'ioi') {
if (!judge_state.pending) { if (!judge_state.pending) {
@ -107,10 +106,13 @@ class ContestPlayer extends Model {
} }
} }
} else if (this.contest.type === 'noi') { } else if (this.contest.type === 'noi') {
if (this.score_details[judge_state.problem_id] && this.score_details[judge_state.problem_id].judge_id > judge_state.id) return;
this.score_details[judge_state.problem_id] = { this.score_details[judge_state.problem_id] = {
score: judge_state.score, score: judge_state.score,
judge_id: judge_state.id judge_id: judge_state.id
}; };
this.score = 0; this.score = 0;
for (let x in this.score_details) { for (let x in this.score_details) {
this.score += this.score_details[x].score; this.score += this.score_details[x].score;
@ -161,7 +163,6 @@ class ContestPlayer extends Model {
} }
} }
} }
});
} }
getModel() { return model; } getModel() { return model; }

Loading…
Cancel
Save