@@ -254,8 +254,7 @@ public function calculateScoreRow(
254
254
Contest $ contest ,
255
255
Team $ team ,
256
256
Problem $ problem ,
257
- bool $ updateRankCache = true ,
258
- bool $ updatePotentialFirstToSolves = true
257
+ bool $ updateRankCache = true
259
258
): void {
260
259
$ this ->logger ->debug (
261
260
"ScoreboardService::calculateScoreRow '%d' '%d' '%d' " ,
@@ -418,7 +417,6 @@ public function calculateScoreRow(
418
417
// See if this submission was the first to solve this problem.
419
418
// Only relevant if it was correct in the first place.
420
419
$ firstToSolve = false ;
421
- $ potentialFirstToSolve = false ;
422
420
if ($ correctJury ) {
423
421
$ params = [
424
422
'cid ' => $ contest ->getCid (),
@@ -439,49 +437,32 @@ public function calculateScoreRow(
439
437
// - or already judged to be correct (if it is judged but not correct,
440
438
// it is not a first to solve)
441
439
// - 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 ' : '' ;
446
441
if ($ useExternalJudgements ) {
447
- $ baseQuery = '
442
+ $ firstToSolve = 0 == $ this -> em -> getConnection ()-> fetchOne ( '
448
443
SELECT count(*) FROM submission s
449
444
LEFT JOIN external_judgement ej USING (submitid)
450
445
LEFT JOIN external_judgement ej2 ON ej2.submitid = s.submitid AND ej2.starttime > ej.starttime
451
446
LEFT JOIN team t USING(teamid)
452
447
LEFT JOIN team_category tc USING (categoryid)
453
448
WHERE s.valid = 1 AND
449
+ (ej.result IS NULL OR ej.result = :correctResult ' .
450
+ $ verificationRequiredExtra .') AND
454
451
s.cid = :cid AND s.probid = :probid AND
455
452
tc.sortorder = :teamSortOrder AND
456
- round(s.submittime,4) < :submitTime ' ;
457
- $ judgingTable = 'ej ' ;
453
+ round(s.submittime,4) < :submitTime ' , $ params );
458
454
} else {
459
- $ baseQuery = '
455
+ $ firstToSolve = 0 == $ this -> em -> getConnection ()-> fetchOne ( '
460
456
SELECT count(*) FROM submission s
461
457
LEFT JOIN judging j ON (s.submitid=j.submitid AND j.valid=1)
462
458
LEFT JOIN team t USING (teamid)
463
459
LEFT JOIN team_category tc USING (categoryid)
464
460
WHERE s.valid = 1 AND
461
+ (j.judgingid IS NULL OR j.result IS NULL OR j.result = :correctResult ' .
462
+ $ verificationRequiredExtra .') AND
465
463
s.cid = :cid AND s.probid = :probid AND
466
464
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 );
485
466
}
486
467
}
487
468
@@ -501,14 +482,13 @@ public function calculateScoreRow(
501
482
'runtimePublic ' => $ runtimePubl === PHP_INT_MAX ? 0 : $ runtimePubl ,
502
483
'isCorrectPublic ' => (int )$ correctPubl ,
503
484
'isFirstToSolve ' => (int )$ firstToSolve ,
504
- 'isPotentialFirstToSolve ' => (int )$ potentialFirstToSolve ,
505
485
];
506
486
$ this ->em ->getConnection ()->executeQuery ('REPLACE INTO scorecache
507
487
(cid, teamid, probid,
508
488
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)
510
490
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 );
512
492
513
493
if ($ this ->em ->getConnection ()->fetchOne ('SELECT RELEASE_LOCK(:lock) ' ,
514
494
['lock ' => $ lockString ]) != 1 ) {
@@ -519,31 +499,6 @@ public function calculateScoreRow(
519
499
if ($ updateRankCache && ($ correctJury || $ correctPubl )) {
520
500
$ this ->updateRankCache ($ contest , $ team );
521
501
}
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
- }
547
502
}
548
503
549
504
/**
0 commit comments