Skip to content

Commit

Permalink
Speed up JudgeHandler's processing of problem list
Browse files Browse the repository at this point in the history
Avoid querying unnecessary data
  • Loading branch information
hieplpvip committed Sep 18, 2023
1 parent 2ecdc1b commit 0376c38
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions judge/bridge/judge_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def _connected(self):
judge = self.judge = Judge.objects.get(name=self.name)
judge.start_time = timezone.now()
judge.online = True
judge.problems.set(Problem.objects.filter(code__in=list(self.problems.keys())))
judge.runtimes.set(Language.objects.filter(key__in=list(self.executors.keys())))
judge.problems.set(Problem.objects.filter(code__in=list(self.problems.keys())).values_list('id', flat=True))
judge.runtimes.set(Language.objects.filter(key__in=list(self.executors.keys())).values_list('id', flat=True))

# Cache is_disabled for faster access
self.is_disabled = judge.is_disabled
Expand Down Expand Up @@ -331,7 +331,9 @@ def on_supported_problems(self, packet):
if not self.working:
self.judges.update_problems(self)

self.judge.problems.set(Problem.objects.filter(code__in=list(self.problems.keys())))
self.judge.problems.set(
Problem.objects.filter(code__in=list(self.problems.keys())).values_list('id', flat=True),
)
json_log.info(self._make_json_log(action='update-problems', count=len(self.problems)))

def on_grading_begin(self, packet):
Expand Down

0 comments on commit 0376c38

Please sign in to comment.