Skip to content

Commit f8f6576

Browse files
committed
Revert "Keep track of potential first to solves so we can update them when we get 'delayed' results."
This reverts commit 9f4dcc0. #2282 was merged by accident and needs more thought.
1 parent bfdca61 commit f8f6576

File tree

5 files changed

+12
-272
lines changed

5 files changed

+12
-272
lines changed

webapp/migrations/Version20231229094359.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

webapp/src/DataFixtures/Test/SampleTeamsFixture.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

webapp/src/Entity/ScoreCache.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ class ScoreCache
9494
])]
9595
private bool $is_first_to_solve = false;
9696

97-
#[ORM\Column(options: [
98-
'comment' => 'Is this potentially the first solution to this problem?',
99-
'default' => 0,
100-
])]
101-
private bool $is_potential_first_to_solve = false;
102-
10397
#[ORM\Id]
10498
#[ORM\ManyToOne]
10599
#[ORM\JoinColumn(name: 'cid', referencedColumnName: 'cid', onDelete: 'CASCADE')]
@@ -236,17 +230,6 @@ public function getIsFirstToSolve() : bool
236230
return $this->is_first_to_solve;
237231
}
238232

239-
public function setIsPotentialFirstToSolve(bool $isPotentialFirstToSolve): ScoreCache
240-
{
241-
$this->is_potential_first_to_solve = $isPotentialFirstToSolve;
242-
return $this;
243-
}
244-
245-
public function getIsPotentialFirstToSolve() : bool
246-
{
247-
return $this->is_potential_first_to_solve;
248-
}
249-
250233
public function setContest(?Contest $contest = null): ScoreCache
251234
{
252235
$this->contest = $contest;

webapp/src/Service/ScoreboardService.php

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ public function calculateScoreRow(
254254
Contest $contest,
255255
Team $team,
256256
Problem $problem,
257-
bool $updateRankCache = true,
258-
bool $updatePotentialFirstToSolves = true
257+
bool $updateRankCache = true
259258
): void {
260259
$this->logger->debug(
261260
"ScoreboardService::calculateScoreRow '%d' '%d' '%d'",
@@ -418,7 +417,6 @@ public function calculateScoreRow(
418417
// See if this submission was the first to solve this problem.
419418
// Only relevant if it was correct in the first place.
420419
$firstToSolve = false;
421-
$potentialFirstToSolve = false;
422420
if ($correctJury) {
423421
$params = [
424422
'cid' => $contest->getCid(),
@@ -439,49 +437,32 @@ public function calculateScoreRow(
439437
// - or already judged to be correct (if it is judged but not correct,
440438
// it is not a first to solve)
441439
// - or the submission is still queued for judgement (judgehost is NULL).
442-
// If there are no valid correct submissions submitted earlier but there
443-
// are submissions awaiting judgement, we are potentially the first to solve.
444-
// We need to keep track of this since we later need to set the actual first to solve.
445-
$verificationRequiredExtra = ($verificationRequired && !$useExternalJudgements) ? 'OR j.verified = 0' : '';
440+
$verificationRequiredExtra = $verificationRequired ? 'OR j.verified = 0' : '';
446441
if ($useExternalJudgements) {
447-
$baseQuery = '
442+
$firstToSolve = 0 == $this->em->getConnection()->fetchOne('
448443
SELECT count(*) FROM submission s
449444
LEFT JOIN external_judgement ej USING (submitid)
450445
LEFT JOIN external_judgement ej2 ON ej2.submitid = s.submitid AND ej2.starttime > ej.starttime
451446
LEFT JOIN team t USING(teamid)
452447
LEFT JOIN team_category tc USING (categoryid)
453448
WHERE s.valid = 1 AND
449+
(ej.result IS NULL OR ej.result = :correctResult '.
450+
$verificationRequiredExtra.') AND
454451
s.cid = :cid AND s.probid = :probid AND
455452
tc.sortorder = :teamSortOrder AND
456-
round(s.submittime,4) < :submitTime';
457-
$judgingTable = 'ej';
453+
round(s.submittime,4) < :submitTime', $params);
458454
} else {
459-
$baseQuery = '
455+
$firstToSolve = 0 == $this->em->getConnection()->fetchOne('
460456
SELECT count(*) FROM submission s
461457
LEFT JOIN judging j ON (s.submitid=j.submitid AND j.valid=1)
462458
LEFT JOIN team t USING (teamid)
463459
LEFT JOIN team_category tc USING (categoryid)
464460
WHERE s.valid = 1 AND
461+
(j.judgingid IS NULL OR j.result IS NULL OR j.result = :correctResult '.
462+
$verificationRequiredExtra.') AND
465463
s.cid = :cid AND s.probid = :probid AND
466464
tc.sortorder = :teamSortOrder AND
467-
round(s.submittime,4) < :submitTime';
468-
$judgingTable = 'j';
469-
}
470-
471-
$numEarlierCorrect = $this->em->getConnection()->fetchOne(
472-
"$baseQuery AND $judgingTable.result = :correctResult",
473-
$params);
474-
$numEarlierPending = $this->em->getConnection()->fetchOne(
475-
"$baseQuery AND ($judgingTable.result IS NULL $verificationRequiredExtra)",
476-
$params);
477-
478-
if ($numEarlierCorrect == 0) {
479-
// This is either a first to solve or potential first to solve
480-
if ($numEarlierPending == 0) {
481-
$firstToSolve = true;
482-
} else {
483-
$potentialFirstToSolve = true;
484-
}
465+
round(s.submittime,4) < :submitTime', $params);
485466
}
486467
}
487468

@@ -501,14 +482,13 @@ public function calculateScoreRow(
501482
'runtimePublic' => $runtimePubl === PHP_INT_MAX ? 0 : $runtimePubl,
502483
'isCorrectPublic' => (int)$correctPubl,
503484
'isFirstToSolve' => (int)$firstToSolve,
504-
'isPotentialFirstToSolve' => (int)$potentialFirstToSolve,
505485
];
506486
$this->em->getConnection()->executeQuery('REPLACE INTO scorecache
507487
(cid, teamid, probid,
508488
submissions_restricted, pending_restricted, solvetime_restricted, runtime_restricted, is_correct_restricted,
509-
submissions_public, pending_public, solvetime_public, runtime_public, is_correct_public, is_first_to_solve, is_potential_first_to_solve)
489+
submissions_public, pending_public, solvetime_public, runtime_public, is_correct_public, is_first_to_solve)
510490
VALUES (:cid, :teamid, :probid, :submissionsRestricted, :pendingRestricted, :solvetimeRestricted, :runtimeRestricted, :isCorrectRestricted,
511-
:submissionsPublic, :pendingPublic, :solvetimePublic, :runtimePublic, :isCorrectPublic, :isFirstToSolve, :isPotentialFirstToSolve)', $params);
491+
:submissionsPublic, :pendingPublic, :solvetimePublic, :runtimePublic, :isCorrectPublic, :isFirstToSolve)', $params);
512492

513493
if ($this->em->getConnection()->fetchOne('SELECT RELEASE_LOCK(:lock)',
514494
['lock' => $lockString]) != 1) {
@@ -519,31 +499,6 @@ public function calculateScoreRow(
519499
if ($updateRankCache && ($correctJury || $correctPubl)) {
520500
$this->updateRankCache($contest, $team);
521501
}
522-
523-
// If we did not have a first to solve, we need to check if we have any
524-
// potential first to solve that are now the first to solve.
525-
// We only do this if there are no pending submissions for this problem
526-
// for this team and if this submission is not a potential first to solve itself.
527-
// We also do this only once, to not have infinite loops if we have multiple
528-
// potential first to solves.
529-
if ($updatePotentialFirstToSolves && $pendingJury === 0 && !$potentialFirstToSolve) {
530-
/** @var ScoreCache[] $potentialFirstToSolves */
531-
$potentialFirstToSolves = $this->em->createQueryBuilder()
532-
->from(ScoreCache::class, 's')
533-
->join('s.team', 't')
534-
->select('s', 't')
535-
->andWhere('s.contest = :contest')
536-
->andWhere('s.problem = :problem')
537-
->andWhere('s.is_potential_first_to_solve = 1')
538-
->setParameter('contest', $contest)
539-
->setParameter('problem', $problem)
540-
->getQuery()
541-
->getResult();
542-
543-
foreach ($potentialFirstToSolves as $row) {
544-
$this->calculateScoreRow($contest, $row->getTeam(), $problem, $updateRankCache, false);
545-
}
546-
}
547502
}
548503

549504
/**

webapp/tests/Unit/Service/ScoreboardServiceTest.php

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)