Browse Source

Fix wrong submit count of problems

master
Menci 8 years ago
parent
commit
4fa9b64f72
  1. 21
      models/judge_state.js
  2. 2
      modules/problem.js

21
models/judge_state.js

@ -139,14 +139,21 @@ class JudgeState extends Model {
this.result = result; this.result = result;
} }
async updateRelatedInfo() { async updateRelatedInfo(newSubmission) {
if (this.type === 0) { if (this.type === 0) {
await this.loadRelationships() if (newSubmission) {
await this.user.refreshSubmitInfo(); await this.loadRelationships();
this.problem.submit_num++; await this.user.refreshSubmitInfo();
if (this.status === 'Accepted') this.problem.ac_num++; this.problem.submit_num++;
await this.user.save(); await this.user.save();
await this.problem.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) { } 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);

2
modules/problem.js

@ -232,12 +232,12 @@ app.post('/submit/:id', async (req, res) => {
judge_state.type_info = contest_id; judge_state.type_info = contest_id;
await judge_state.save(); await judge_state.save();
await judge_state.updateRelatedInfo();
} else { } else {
if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied.'; if (!await problem.isAllowedUseBy(res.locals.user)) throw 'Permission denied.';
judge_state.type = problem.is_public ? 0 : 2; judge_state.type = problem.is_public ? 0 : 2;
await judge_state.save(); await judge_state.save();
} }
await judge_state.updateRelatedInfo(true);
let waiting_judge = await WaitingJudge.create({ let waiting_judge = await WaitingJudge.create({
judge_id: judge_state.id judge_id: judge_state.id

Loading…
Cancel
Save