diff --git a/models/judge_state.js b/models/judge_state.js index 8c429ff..1943b91 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -173,24 +173,28 @@ class JudgeState extends Model { } async updateRelatedInfo(newSubmission) { - if (this.type === 0) { - if (newSubmission) { - await this.loadRelationships(); - await this.user.refreshSubmitInfo(); - this.problem.submit_num++; - await this.user.save(); - await this.problem.save(); - } else if (this.status === 'Accepted') { - await this.loadRelationships(); - await this.user.refreshSubmitInfo(); - this.problem.ac_num++; - await this.user.save(); - await this.problem.save(); - } - } else if (this.type === 1) { - let contest = await Contest.fromID(this.type_info); - await contest.newSubmission(this); - } + await syzoj.utils.lock(['JudgeState::updateRelatedInfo', 'problem', this.problem_id], async () => { + await syzoj.utils.lock(['JudgeState::updateRelatedInfo', 'user', this.user_id], async () => { + if (this.type === 0) { + if (newSubmission) { + await this.loadRelationships(); + await this.user.refreshSubmitInfo(); + this.problem.submit_num++; + await this.user.save(); + await this.problem.save(); + } else if (this.status === 'Accepted') { + await this.loadRelationships(); + await this.user.refreshSubmitInfo(); + this.problem.ac_num++; + await this.user.save(); + await this.problem.save(); + } + } else if (this.type === 1) { + let contest = await Contest.fromID(this.type_info); + await contest.newSubmission(this); + } + }); + }); } async rejudge() {