Skip to content

Commit fe79066

Browse files
committed
Transaction free update of filtered internalError update
1 parent 62803f1 commit fe79066

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
@@ -868,32 +868,24 @@ public function internalErrorAction(Request $request): ?int
868868

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

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

0 commit comments

Comments
 (0)