Skip to content

Commit

Permalink
Transaction free update of filtered internalError update
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupke committed Feb 28, 2025
1 parent ecb22f3 commit ada0e53
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,32 +853,23 @@ public function internalErrorAction(Request $request): ?int

if ($field_name !== null) {
// Disable any outstanding judgetasks with the same script that have not been claimed yet.
$this->em->wrapInTransaction(function (EntityManager $em) use ($field_name, $disabled_id, $error) {
$judgingids = $em->getConnection()->executeQuery(
'SELECT DISTINCT jobid'
. ' FROM judgetask'
. ' WHERE ' . $field_name . ' = :id'
. ' AND judgehostid IS NULL'
. ' AND valid = 1',
[
'id' => $disabled_id,
]
)->fetchFirstColumn();
$judgings = $em->getRepository(Judging::class)->findBy(['judgingid' => $judgingids]);
foreach ($judgings as $judging) {
/** @var Judging $judging */
$judging->setInternalError($error);
}
$em->flush();
$em->getConnection()->executeStatement(
'UPDATE judgetask SET valid=0'
. ' WHERE ' . $field_name . ' = :id'
. ' AND judgehostid IS NULL',
[
'id' => $disabled_id,
]
);
});
$rows = $this->em->createQueryBuilder()
->update(Judging::class, 'j')
->leftJoin(JudgeTask::class, 'jt', Join::WITH, 'jt.jobid = j.judgingid')
->set('j.internal_error', $error)
->set('jt.valid', 0)
->where('jt.' . $field_name . ' = :id')
->andWhere('j.internal_error IS NULL')
->andWhere('jt.judgehost_id IS NULL')
->andWhere('jt.valid = 1')
->setParameter('id', $disabled_id)
->distinct()
->getQuery()
->getArrayResult();

if ($rows == 0) {
// TODO, handle this case. Nothing was updated.
}
}

$this->dj->setInternalError($disabled, $contest, false);
Expand Down

0 comments on commit ada0e53

Please sign in to comment.