Skip to content

Commit 3b38b7a

Browse files
committed
Transaction free update of filtered internalError update
1 parent 4bb76e4 commit 3b38b7a

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

webapp/src/Controller/API/JudgehostController.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -864,32 +864,23 @@ public function internalErrorAction(Request $request): ?int
864864

865865
if ($field_name !== null) {
866866
// Disable any outstanding judgetasks with the same script that have not been claimed yet.
867-
$this->em->wrapInTransaction(function (EntityManager $em) use ($field_name, $disabled_id, $error) {
868-
$judgingids = $em->getConnection()->executeQuery(
869-
'SELECT DISTINCT jobid'
870-
. ' FROM judgetask'
871-
. ' WHERE ' . $field_name . ' = :id'
872-
. ' AND judgehostid IS NULL'
873-
. ' AND valid = 1',
874-
[
875-
'id' => $disabled_id,
876-
]
877-
)->fetchFirstColumn();
878-
$judgings = $em->getRepository(Judging::class)->findBy(['judgingid' => $judgingids]);
879-
foreach ($judgings as $judging) {
880-
/** @var Judging $judging */
881-
$judging->setInternalError($error);
882-
}
883-
$em->flush();
884-
$em->getConnection()->executeStatement(
885-
'UPDATE judgetask SET valid=0'
886-
. ' WHERE ' . $field_name . ' = :id'
887-
. ' AND judgehostid IS NULL',
888-
[
889-
'id' => $disabled_id,
890-
]
891-
);
892-
});
867+
$rows = $this->em->createQueryBuilder()
868+
->update(Judging::class, 'j')
869+
->leftJoin(JudgeTask::class, 'jt')
870+
->set('j.internal_error', $error)
871+
->set('jt.valid', 0)
872+
->where('jt.' . $field_name . ' = :id')
873+
->andWhere('j.internal_error IS NULL')
874+
->andWhere('jt.judgehost_id IS NULL')
875+
->andWhere('jt.valid = 1')
876+
->setParameter('id', $disabled_id)
877+
->distinct()
878+
->getQuery()
879+
->getArrayResult();
880+
881+
if ($rows == 0) {
882+
// TODO, handle this case. Nothing was updated.
883+
}
893884
}
894885

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

0 commit comments

Comments
 (0)