Skip to content

Commit c68a9f5

Browse files
committed
Uses the baloonservice for the updates
The computation for which balloons need to be sent out is a bit more complex than before. Reusing the logic of the BalloonService keeps it nice and DRY.
1 parent 90fa34f commit c68a9f5

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

webapp/src/Service/DOMJudgeService.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class DOMJudgeService
101101

102102
public function __construct(
103103
protected readonly EntityManagerInterface $em,
104+
protected readonly BalloonService $balloonService,
104105
protected readonly LoggerInterface $logger,
105106
protected readonly RequestStack $requestStack,
106107
protected readonly ParameterBagInterface $params,
@@ -437,26 +438,14 @@ public function getUpdates(): array
437438
}
438439

439440
if ($this->checkrole('balloon') && $contest) {
440-
$balloonsQuery = $this->em->createQueryBuilder()
441-
->select('b.balloonid', 't.name', 't.location', 'p.name AS pname')
442-
->from(Balloon::class, 'b')
443-
->leftJoin('b.submission', 's')
444-
->leftJoin('s.problem', 'p')
445-
->leftJoin('s.contest', 'co')
446-
->leftJoin('p.contest_problems', 'cp', Join::WITH, 'co.cid = cp.contest AND p.probid = cp.problem')
447-
->leftJoin('s.team', 't')
448-
->andWhere('co.cid = :cid')
449-
->andWhere('b.done = 0')
450-
->setParameter('cid', $contest->getCid());
451-
452-
$freezetime = $contest->getFreezeTime();
453-
if ($freezetime !== null && !(bool)$this->config->get('show_balloons_postfreeze')) {
454-
$balloonsQuery
455-
->andWhere('s.submittime < :freeze')
456-
->setParameter('freeze', $freezetime);
457-
}
458-
459-
$balloons = $balloonsQuery->getQuery()->getResult();
441+
$balloons = array_map(function ($balloon) {
442+
return [
443+
'balloonid' => $balloon['data']['balloonid'],
444+
'name' => $balloon['data']['team']->getName(),
445+
'location' => $balloon['data']['location'],
446+
'pname' => $balloon['data']['contestproblem']->getProblem()->getName(),
447+
];
448+
}, $this->balloonService->collectBalloonTable($contest, true));
460449
}
461450

462451
return [

0 commit comments

Comments
 (0)