Skip to content

Removes unneeded transactions. #2909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,32 +866,24 @@ 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')
->set('j.internal_error', ':error')
->set('jt.valid', 0)
->andWhere('jt.' . $field_name . ' = :id')
->andWhere('j.internal_error IS NULL')
->andWhere('jt.judgehost_id IS NULL')
->andWhere('jt.valid = 1')
->setParameter('error', $error)
->setParameter('id', $disabled_id)
->distinct()
->getQuery()
->getArrayResult();

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything to be handled? If there is no outstanding that we would disable here, we don't have an issue, do we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, I'll remove.

Reading this back, this cannot be correct! I've had to create a manual query for updates with joins. 🤯

Apparently this case is never hit in the testsuite either.

}
}

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