Skip to content

Commit 81497f7

Browse files
committed
Transaction free update of filtered internalError update
1 parent 45d6ebb commit 81497f7

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

webapp/src/Controller/API/JudgehostController.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -866,32 +866,24 @@ public function internalErrorAction(Request $request): ?int
866866

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

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

0 commit comments

Comments
 (0)