From ada0e53f3952c317229eca1b8d4c22486c6e722f Mon Sep 17 00:00:00 2001 From: Mart Pluijmaekers Date: Fri, 28 Feb 2025 16:25:35 +0100 Subject: [PATCH] Transaction free update of filtered internalError update --- .../Controller/API/JudgehostController.php | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/webapp/src/Controller/API/JudgehostController.php b/webapp/src/Controller/API/JudgehostController.php index c1fdab55db..672213f20f 100644 --- a/webapp/src/Controller/API/JudgehostController.php +++ b/webapp/src/Controller/API/JudgehostController.php @@ -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);