From 4fa9b64f72aaee2888f3ac52bc2b30013902dae3 Mon Sep 17 00:00:00 2001 From: Menci Date: Sun, 18 Dec 2016 09:33:47 +0800 Subject: [PATCH] Fix wrong submit count of problems --- models/judge_state.js | 21 ++++++++++++++------- modules/problem.js | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/models/judge_state.js b/models/judge_state.js index c8efa35..3735f20 100644 --- a/models/judge_state.js +++ b/models/judge_state.js @@ -139,14 +139,21 @@ class JudgeState extends Model { this.result = result; } - async updateRelatedInfo() { + async updateRelatedInfo(newSubmission) { if (this.type === 0) { - await this.loadRelationships() - await this.user.refreshSubmitInfo(); - this.problem.submit_num++; - if (this.status === 'Accepted') this.problem.ac_num++; - await this.user.save(); - await this.problem.save(); + 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); diff --git a/modules/problem.js b/modules/problem.js index 3cf3a7f..1b6a159 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -232,12 +232,12 @@ app.post('/submit/:id', async (req, res) => { judge_state.type_info = contest_id; await judge_state.save(); - await judge_state.updateRelatedInfo(); } else { if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied.'; judge_state.type = problem.is_public ? 0 : 2; await judge_state.save(); } + await judge_state.updateRelatedInfo(true); let waiting_judge = await WaitingJudge.create({ judge_id: judge_state.id