From d171207b7dbeb4c321276b8e7fc568d2ed3757dd Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 15 Apr 2019 00:15:41 +0800 Subject: [PATCH] Fix deadlock in JudgeState::updateRelatedInfo() --- models/judge_state.js | 23 ++++++++++------------- models/problem.js | 2 +- models/user.js | 2 ++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/models/judge_state.js b/models/judge_state.js index 025cb5d..f937c2a 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -118,19 +118,16 @@ class JudgeState extends Model { } async updateRelatedInfo(newSubmission) { - 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) { - await this.loadRelationships(); - await this.user.refreshSubmitInfo(); - await this.user.save(); - await this.problem.resetSubmissionCount(); - } else if (this.type === 1) { - let contest = await Contest.fromID(this.type_info); - await contest.newSubmission(this); - } - }); - }); + if (this.type === 0) { + await this.loadRelationships(); + + // No need to await them. + this.user.refreshSubmitInfo(); + this.problem.resetSubmissionCount(); + } else if (this.type === 1) { + let contest = await Contest.fromID(this.type_info); + await contest.newSubmission(this); + } } async rejudge() { diff --git a/models/problem.js b/models/problem.js index 6c5ecf0..a7ab9b7 100644 --- a/models/problem.js +++ b/models/problem.js @@ -490,7 +490,7 @@ class Problem extends Model { async resetSubmissionCount() { let JudgeState = syzoj.model('judge_state'); await syzoj.utils.lock(['Problem::resetSubmissionCount', this.id], async () => { - this.submit_num = await JudgeState.count({ score: { $not: null }, problem_id: this.id, type: { $not: 1 } }); + this.submit_num = await JudgeState.count({ problem_id: this.id, type: { $not: 1 } }); this.ac_num = await JudgeState.count({ score: 100, problem_id: this.id, type: { $not: 1 } }); await this.save(); }); diff --git a/models/user.js b/models/user.js index 4f215e4..c67c475 100644 --- a/models/user.js +++ b/models/user.js @@ -108,6 +108,8 @@ class User extends Model { }); this.submit_num = cnt; + + await this.save(); }); }