From fbd1d865faad69118fa3e23646352eb8740ced95 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 27 May 2023 08:33:19 +0700 Subject: [PATCH] Try optimizing batch rejudge --- judge/judgeapi.py | 5 +++-- judge/tasks/submission.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/judge/judgeapi.py b/judge/judgeapi.py index 96a2153..dd02898 100644 --- a/judge/judgeapi.py +++ b/judge/judgeapi.py @@ -56,7 +56,7 @@ def judge_request(packet, reply=True): return result -def judge_submission(submission, rejudge=False, batch_rejudge=False, judge_id=None): +def judge_submission(submission, rejudge=False, batch_rejudge=False, judge_id=None, delete_testcases=True): from .models import ContestSubmission, Submission, SubmissionTestCase CONTEST_SUBMISSION_PRIORITY = 0 @@ -101,7 +101,8 @@ def judge_submission(submission, rejudge=False, batch_rejudge=False, judge_id=No ): return False - SubmissionTestCase.objects.filter(submission_id=submission.id).delete() + if delete_testcases: + SubmissionTestCase.objects.filter(submission_id=submission.id).delete() try: response = judge_request( diff --git a/judge/tasks/submission.py b/judge/tasks/submission.py index aa474f8..3cc32ad 100644 --- a/judge/tasks/submission.py +++ b/judge/tasks/submission.py @@ -2,7 +2,7 @@ from celery import shared_task from django.core.cache import cache from django.utils.translation import gettext as _ -from judge.models import Problem, Profile, Submission +from judge.models import Problem, Profile, Submission, SubmissionTestCase from judge.utils.celery import Progress __all__ = ("apply_submission_filter", "rejudge_problem_filter", "rescore_problem") @@ -30,9 +30,15 @@ def rejudge_problem_filter( queryset = apply_submission_filter(queryset, id_range, languages, results, contest) rejudged = 0 - with Progress(self, queryset.count()) as p: + with Progress(self, queryset.count() * 2) as p: + for submission in queryset: + SubmissionTestCase.objects.filter(submission_id=submission.id).delete() + rejudged += 1 + if rejudged % 10 == 0: + p.done = rejudged + for submission in queryset.iterator(): - submission.judge(rejudge=True, batch_rejudge=True) + submission.judge(rejudge=True, batch_rejudge=True, delete_testcases=False) rejudged += 1 if rejudged % 10 == 0: p.done = rejudged