diff --git a/models/judge_state.js b/models/judge_state.js index f1f7933..ee6efc6 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -136,19 +136,10 @@ class JudgeState extends Model { 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(); - } + 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); @@ -186,17 +177,13 @@ class JudgeState extends Model { await waiting_judge.save(); */ + await this.problem.resetSubmissionCount(); if (oldStatus === 'Accepted') { await this.user.refreshSubmitInfo(); await this.user.save(); } - if (this.type === 0) { - if (oldStatus === 'Accepted') { - this.problem.ac_num--; - await this.problem.save(); - } - } else if (this.type === 1) { + if (this.type === 1) { let contest = await Contest.fromID(this.type_info); await contest.newSubmission(this); } diff --git a/models/problem.js b/models/problem.js index 2b8a1f8..c5081c1 100644 --- a/models/problem.js +++ b/models/problem.js @@ -498,9 +498,11 @@ class Problem extends Model { } async resetSubmissionCount() { - this.submit_num = await JudgeState.count({ score: { $not: null }, problem_id: this.id }); - this.ac_num = await JudgeState.count({ score: 100, problem_id: this.id }); - await this.save(); + 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.ac_num = await JudgeState.count({ score: 100, problem_id: this.id, $type: { $not: 1 } }); + await this.save(); + }); } // type: fastest / slowest / shortest / longest / earliest