Skip to content

Commit 77928f7

Browse files
committed
Try to do everything with shorter queries
Probably we can even do this with one by using leftJoins and checking if any of the columns we need become NON NULL but that makes it a lot harder to get right in the next iteration.
1 parent 8ffa050 commit 77928f7

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

webapp/src/Service/DOMJudgeService.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,65 @@ public function getSamplesZipStreamedResponse(ContestProblem $contestProblem): S
879879
return Utils::streamAsBinaryFile($zipFileContent, $outputFilename, 'zip');
880880
}
881881

882+
public function checkIfSamplesZipForContest(Contest $contest): bool
883+
{
884+
// Note, we reload the contest with the problems and attachments, to reduce the number of queries
885+
// We do not load the testcases here since addSamplesToZip loads them
886+
$contestQuery = $this->em->createQueryBuilder()
887+
->from(Contest::class, 'c')
888+
->innerJoin('c.problems', 'cp')
889+
->innerJoin('cp.problem', 'p')
890+
->leftJoin('p.attachments', 'a')
891+
->leftJoin('p.problemStatementContent', 'content')
892+
->select('c', 'cp', 'p', 'a', 'content')
893+
->andWhere('c.cid = :cid')
894+
->andWhere('cp.allowSubmit = 1') // Do we need this...
895+
->setParameter('cid', $contest->getCid());
896+
897+
/** @var Contest $contest */
898+
$contest = $contestQuery->getQuery()->getSingleResult();
899+
900+
if ($contest->getContestProblemsetType()) {
901+
return true;
902+
}
903+
904+
/** @var Problem[] $nonInteractiveProblems */
905+
$nonInteractiveProblems = $contestQuery
906+
->innerJoin('p.testcases', 'tc')
907+
->andWhere('tc.sample = 1')
908+
->andWhere('BIT_AND(p.types, :interactiveType) = 0')
909+
->setParameter('interactiveType', Problem::TYPE_INTERACTIVE)
910+
->getQuery()
911+
->getResult();
912+
if (!empty($nonInteractiveProblems)) {
913+
return true;
914+
}
915+
916+
/** @var Problem[] $problemsWithProblemStatement */
917+
$problemsWithProblemStatement = $contestQuery
918+
->andWhere('p.problemstatementFile IS NOT NULL')
919+
->getQuery()
920+
->getResult();
921+
if (!empty($problemsWithProblemStatement)) {
922+
return true;
923+
}
924+
925+
/** @var Problem[] $problemsWithAttachments */
926+
$problemsWithAttachments = $contestQuery
927+
->innerJoin('p.attachments', 'a')
928+
->getQuery()
929+
->getResult();
930+
if (!empty($problemsWithAttachments)) {
931+
return true;
932+
}
933+
934+
return false;
935+
}
936+
882937
public function getSamplesZipForContest(Contest $contest): StreamedResponse
883938
{
939+
// When updating this, also update checkIfSamplesZipForContest.
940+
884941
// Note, we reload the contest with the problems and attachments, to reduce the number of queries
885942
// We do not load the testcases here since addSamplesToZip loads them
886943
/** @var Contest $contest */

0 commit comments

Comments
 (0)