Browse Source

Fix deadlock in JudgeState::updateRelatedInfo()

pull/6/head
Menci 5 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) {
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() {

2
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();
});

2
models/user.js

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

Loading…
Cancel
Save