Browse Source

Fix deadlock in JudgeState::updateRelatedInfo()

pull/6/head
Menci 6 years ago
parent
commit
d171207b7d
  1. 23
      models/judge_state.js
  2. 2
      models/problem.js
  3. 2
      models/user.js

23
models/judge_state.js

@ -118,19 +118,16 @@ class JudgeState extends Model {
} }
async updateRelatedInfo(newSubmission) { async updateRelatedInfo(newSubmission) {
await syzoj.utils.lock(['JudgeState::updateRelatedInfo', 'problem', this.problem_id], async () => { if (this.type === 0) {
await syzoj.utils.lock(['JudgeState::updateRelatedInfo', 'user', this.user_id], async () => { await this.loadRelationships();
if (this.type === 0) {
await this.loadRelationships(); // No need to await them.
await this.user.refreshSubmitInfo(); this.user.refreshSubmitInfo();
await this.user.save(); this.problem.resetSubmissionCount();
await this.problem.resetSubmissionCount(); } else if (this.type === 1) {
} else if (this.type === 1) { let contest = await Contest.fromID(this.type_info);
let contest = await Contest.fromID(this.type_info); await contest.newSubmission(this);
await contest.newSubmission(this); }
}
});
});
} }
async rejudge() { async rejudge() {

2
models/problem.js

@ -490,7 +490,7 @@ class Problem extends Model {
async resetSubmissionCount() { async resetSubmissionCount() {
let JudgeState = syzoj.model('judge_state'); let JudgeState = syzoj.model('judge_state');
await syzoj.utils.lock(['Problem::resetSubmissionCount', this.id], async () => { 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 } }); this.ac_num = await JudgeState.count({ score: 100, problem_id: this.id, type: { $not: 1 } });
await this.save(); await this.save();
}); });

2
models/user.js

@ -108,6 +108,8 @@ class User extends Model {
}); });
this.submit_num = cnt; this.submit_num = cnt;
await this.save();
}); });
} }

Loading…
Cancel
Save