refactor(contest): finalTest database transaction
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2023-02-20 09:45:40 +08:00
parent c2fdca91cd
commit d7741c2910
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
5 changed files with 310 additions and 295 deletions

View File

@ -185,7 +185,7 @@ CREATE TABLE `contests` (
`zan` int NOT NULL DEFAULT '0', `zan` int NOT NULL DEFAULT '0',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `status` (`status`,`id`) USING BTREE KEY `status` (`status`,`id`) USING BTREE
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -337,7 +337,7 @@ CREATE TABLE `contests_submissions` (
`cnt` int DEFAULT NULL, `cnt` int DEFAULT NULL,
`n_failures` int DEFAULT NULL, `n_failures` int DEFAULT NULL,
PRIMARY KEY (`contest_id`,`submitter`,`problem_id`) PRIMARY KEY (`contest_id`,`submitter`,`problem_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --

View File

@ -191,20 +191,22 @@ class UOJContest {
ignore_user_abort(true); ignore_user_abort(true);
set_time_limit(0); set_time_limit(0);
DB::update([ DB::transaction(function () {
"update contests", $status = DB::selectSingle([
"set", ["status" => 'testing'], "select status from contests",
"where", ["id" => $this->info['id']] "where", ["id" => $this->info['id']],
DB::for_update(),
]); ]);
if (DB::affected_rows() !== 1) { if ($status !== 'unfinished') {
// 已经有其他人开始评测了,不进行任何操作 // 已经有其他人开始评测了,不进行任何操作
return; return;
} }
$res = DB::selectAll([ $res = DB::selectAll([
"select id, problem_id, content, result, submitter, hide_score_to_others from submissions", "select id, problem_id, content, result, submitter, hide_score_to_others from submissions",
"where", ["contest_id" => $this->info['id']] "where", ["contest_id" => $this->info['id']],
DB::for_update(),
]); ]);
foreach ($res as $submission) { foreach ($res as $submission) {
$content = json_decode($submission['content'], true); $content = json_decode($submission['content'], true);
@ -299,6 +301,17 @@ class UOJContest {
} }
$updated[$submitter][$pid] = true; $updated[$submitter][$pid] = true;
} }
DB::update([
"update contests",
"set", [
"status" => "testing",
],
"where", [
"id" => $this->info['id'],
],
]);
});
} }
public function queryJudgeProgress() { public function queryJudgeProgress() {

View File

@ -1,5 +1,7 @@
-- InnoDB -- InnoDB
ALTER TABLE `best_ac_submissions` ENGINE=InnoDB TABLESPACE `innodb_system`; ALTER TABLE `best_ac_submissions` ENGINE=InnoDB TABLESPACE `innodb_system`;
ALTER TABLE `contests` ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `contests_submissions` ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `judger_info` COLLATE=utf8mb4_unicode_ci; ALTER TABLE `judger_info` COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `problems_contents` COLLATE=utf8mb4_unicode_ci; ALTER TABLE `problems_contents` COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `submissions` ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ALTER TABLE `submissions` ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;