Skip to content

Commit 345932d

Browse files
committed
Properly implement the troolean
In the past we had a fake troolean: null (pick from somewhere else) true (do lazy) false (do every testcase) Now we have actually a fake 4-way boolean: 1-3 lazy, ondemand & full 0 default
1 parent 0ba5cf5 commit 345932d

File tree

7 files changed

+46
-13
lines changed

7 files changed

+46
-13
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
final class Version20240319140330 extends AbstractMigration
11+
{
12+
public function getDescription(): string
13+
{
14+
return 'Convert default `null` to `0` when the global value should be picked.';
15+
}
16+
17+
public function up(Schema $schema): void
18+
{
19+
$this->addSql('UPDATE contestproblem SET lazy_eval_results = 0 WHERE lazy_eval_results IS NULL');
20+
$this->addSql('ALTER TABLE contestproblem CHANGE lazy_eval_results lazy_eval_results INT UNSIGNED NOT NULL COMMENT \'Whether to do lazy evaluation for this problem; if set this overrides the global configuration setting\'');
21+
}
22+
23+
public function down(Schema $schema): void
24+
{
25+
$this->addSql('ALTER TABLE contestproblem CHANGE lazy_eval_results lazy_eval_results INT UNSIGNED DEFAULT NULL COMMENT \'Whether to do lazy evaluation for this problem; if set this overrides the global configuration setting\'');
26+
$this->addSql('UPDATE contestproblem SET lazy_eval_results = NULL WHERE lazy_eval_results = 0');
27+
}
28+
29+
public function isTransactional(): bool
30+
{
31+
return false;
32+
}
33+
}

webapp/src/Controller/API/JudgehostController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ private function addSingleJudgingRun(
994994
// Lookup global lazy evaluation of results setting and possible problem specific override.
995995
$lazyEval = $this->config->get('lazy_eval_results');
996996
$problemLazy = $judging->getSubmission()->getContestProblem()->getLazyEvalResults();
997-
if (isset($problemLazy)) {
997+
if ($problemLazy !== DOMJudgeService::EVAL_DEFAULT) {
998998
$lazyEval = $problemLazy;
999999
}
10001000

webapp/src/Controller/API/ProblemController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ public function linkProblemAction(
332332

333333
$contest = $this->em->getRepository(Contest::class)->find($this->getContestId($request));
334334

335-
$lazyEvalResults = null;
336-
if ($contestProblemPut->lazyEvalResults !== null) {
335+
$lazyEvalResults = 0;
336+
if ($contestProblemPut->lazyEvalResults !== DOMJudgeService::LAZY_DEFAULT) {
337337
$lazyEvalResults = (int)$contestProblemPut->lazyEvalResults;
338338
}
339339

webapp/src/DataTransferObject/ContestProblemPut.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function __construct(
1616
public readonly ?string $rgb,
1717
#[OA\Property(description: 'The number of points for the problem to add. Defaults to 1')]
1818
public readonly int $points = 1,
19-
#[OA\Property(description: 'Whether to use lazy evaluation for this problem. Defaults to the global setting', nullable: true)]
20-
public readonly ?bool $lazyEvalResults = null,
19+
#[OA\Property(description: 'Whether to use lazy evaluation for this problem. Defaults to the global setting')]
20+
public readonly int $lazyEvalResults = 0,
2121
) {}
2222
}

webapp/src/Entity/ContestProblem.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ class ContestProblem
7171
private ?string $color = null;
7272

7373
#[ORM\Column(
74-
nullable: true,
74+
nullable: false,
7575
options: ['comment' => 'Whether to do lazy evaluation for this problem; if set this overrides the global configuration setting', 'unsigned' => true]
7676
)]
7777
#[Serializer\Exclude]
78-
private ?int $lazyEvalResults = null;
78+
private int $lazyEvalResults = 0;
7979

8080
#[ORM\Id]
8181
#[ORM\ManyToOne(inversedBy: 'problems')]
@@ -193,13 +193,13 @@ public function getApiColor(): ?string
193193
return Utils::convertToColor($this->getColor());
194194
}
195195

196-
public function setLazyEvalResults(?int $lazyEvalResults): ContestProblem
196+
public function setLazyEvalResults(int $lazyEvalResults): ContestProblem
197197
{
198-
$this->lazyEvalResults = $lazyEvalResults === 0 ? null : $lazyEvalResults;
198+
$this->lazyEvalResults = $lazyEvalResults;
199199
return $this;
200200
}
201201

202-
public function getLazyEvalResults(): ?int
202+
public function getLazyEvalResults(): int
203203
{
204204
return $this->lazyEvalResults;
205205
}

webapp/src/Form/Type/ContestProblemType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5858
$builder->add('lazyEvalResults', ChoiceType::class, [
5959
'label' => 'Lazy eval',
6060
'choices' => [
61-
'Default' => null,
61+
'Default' => DJS::EVAL_DEFAULT,
6262
'Yes' => DJS::EVAL_LAZY,
6363
'No' => DJS::EVAL_FULL,
6464
'On demand' => DJS::EVAL_DEMAND,

webapp/src/Service/DOMJudgeService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class DOMJudgeService
7070
final public const DATA_SOURCE_LOCAL = 0;
7171
final public const DATA_SOURCE_CONFIGURATION_EXTERNAL = 1;
7272
final public const DATA_SOURCE_CONFIGURATION_AND_LIVE_EXTERNAL = 2;
73-
final public const EVAL_DEFAULT = null;
73+
final public const EVAL_DEFAULT = 0;
7474
final public const EVAL_LAZY = 1;
7575
final public const EVAL_FULL = 2;
7676
final public const EVAL_DEMAND = 3;
@@ -1163,7 +1163,7 @@ public function maybeCreateJudgeTasks(Judging $judging, int $priority = JudgeTas
11631163

11641164
$evalOnDemand = false;
11651165
// We have 2 cases, the problem picks the global value or the value is set.
1166-
if (((int)$problem->getLazyEvalResults() === (int)DOMJudgeService::EVAL_DEFAULT && $this->config->get('lazy_eval_results') === static::EVAL_DEMAND)
1166+
if (($problem->getLazyEvalResults() === DOMJudgeService::EVAL_DEFAULT && $this->config->get('lazy_eval_results') === static::EVAL_DEMAND)
11671167
|| $problem->getLazyEvalResults() === DOMJudgeService::EVAL_DEMAND) {
11681168
$evalOnDemand = true;
11691169
}

0 commit comments

Comments
 (0)