Skip to content

Commit

Permalink
sim: reselect final submissions; they might have been selected wrongly
Browse files Browse the repository at this point in the history
  • Loading branch information
varqox committed Nov 5, 2024
1 parent 29b89ff commit 6224398
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 108 deletions.
4 changes: 2 additions & 2 deletions subprojects/sim/src/sim/db/schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ const DbSchema& get_schema() {
{
// clang-format off
.create_table_sql = concat_tostr(
"CREATE TABLE `schema_subversion_0` ("
"CREATE TABLE `schema_subversion_1` ("
" `x` bit(1) NOT NULL"
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin"
),
Expand Down Expand Up @@ -501,7 +501,7 @@ const DbSchema& get_schema() {
std::pair{std::string_view{"problem_tags"}, ProblemTag::COLUMNS_NUM},
std::pair{std::string_view{"problems"}, Problem::COLUMNS_NUM},
std::pair{std::string_view{"reupload_problem_jobs"}, ReuploadProblemJob::COLUMNS_NUM},
std::pair{std::string_view{"schema_subversion_0"}, size_t{1}},
std::pair{std::string_view{"schema_subversion_1"}, size_t{1}},
std::pair{std::string_view{"sessions"}, Session::COLUMNS_NUM},
std::pair{std::string_view{"submissions"}, Submission::COLUMNS_NUM},
std::pair{std::string_view{"users"}, User::COLUMNS_NUM},
Expand Down
121 changes: 15 additions & 106 deletions subprojects/sim/src/sim_upgrader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,120 +40,29 @@ run_command(const vector<string>& args, const Spawner::Options& options = {}) {

// Update the below hash and body of the function do_perform_upgrade()
constexpr StringView NORMALIZED_SCHEMA_HASH_BEFORE_UPGRADE =
"d9ec1b212056603054feaad1a606b234a361a838aa58cd21ee6b67f1f2460f9f";
"3317e654e277383a7bcec5cc93d6d8f351f3d67d0af7123e245cf37296aa9e44";

static void do_perform_upgrade(
[[maybe_unused]] const string& sim_dir, [[maybe_unused]] sim::mysql::Connection& mysql
) {
STACK_UNWINDING_MARK;

// Upgrade here
mysql.execute("ALTER TABLE submissions DROP KEY contest_problem_final");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_2");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_3");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_4");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_5");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_6");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_7");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_8");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_9");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_10");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_11");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_12");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_13");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_14");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_15");
mysql.execute("ALTER TABLE submissions DROP KEY user_id_16");
mysql.execute("ALTER TABLE submissions DROP KEY problem_id_2");
mysql.execute("ALTER TABLE submissions DROP KEY contest_id_2");
mysql.execute("ALTER TABLE submissions DROP KEY contest_problem_id_2");
mysql.execute("ALTER TABLE submissions DROP KEY contest_round_id_2");
mysql.execute("ALTER TABLE submissions DROP KEY contest_final");
mysql.execute("ALTER TABLE submissions DROP KEY contest_initial_final");
mysql.execute("ALTER TABLE submissions DROP KEY contest_round_final");
mysql.execute("ALTER TABLE submissions DROP KEY contest_initial_round_final");
mysql.execute("ALTER TABLE submissions DROP KEY contest_initial_problem_final");
mysql.execute("ALTER TABLE submissions DROP KEY initial_final");
mysql.execute("ALTER TABLE submissions ADD KEY `problem_final` (`problem_final`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_problem_final` (`contest_problem_final`,`id`)"
decltype(sim::submissions::Submission::user_id) submission_user_id;
decltype(sim::submissions::Submission::problem_id) submission_problem_id;
decltype(sim::submissions::Submission::contest_problem_id) submission_contest_problem_id;
auto stmt = mysql.execute(
sim::sql::Select("UNIQUE user_id, problem_id, contest_problem_id").from("submissions")
);
mysql.execute(
"ALTER TABLE submissions ADD KEY `user_id_problem_final` (`user_id`,`problem_final`,`id`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY `user_id_contest_problem_final` "
"(`user_id`,`contest_problem_final`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `user_id_type` (`user_id`,`type`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `problem_id_problem_final` "
"(`problem_id`,`problem_final`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `problem_id_contest_problem_final` "
"(`problem_id`,`contest_problem_final`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `problem_id_type` (`problem_id`,`type`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `problem_id_user_id` (`problem_id`,`user_id`,`id`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY `problem_id_user_id_problem_final` "
"(`problem_id`,`user_id`,`problem_final`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `problem_id_user_id_contest_problem_final` "
"(`problem_id`,`user_id`,`contest_problem_final`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `problem_id_user_id_type` "
"(`problem_id`,`user_id`,`type`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `contest_id_type` (`contest_id`,`type`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `contest_id_contest_problem_final` "
"(`contest_id`,`contest_problem_final`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `contest_id_contest_problem_initial_final` "
"(`contest_id`,`contest_problem_initial_final`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_id_user_id` (`contest_id`,`user_id`,`id`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY `contest_id_user_id_type` "
"(`contest_id`,`user_id`,`type`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `contest_id_user_id_contest_problem_final` "
"(`contest_id`,`user_id`,`contest_problem_final`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_id_user_id_contest_problem_initial_final` "
"(`contest_id`,`user_id`,`contest_problem_initial_final`,`id`)"
);
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_round_id_type` (`contest_round_id`,`type`,`id`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY `contest_round_id_contest_problem_final` "
"(`contest_round_id`,`contest_problem_final`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_round_id_contest_problem_initial_final` "
"(`contest_round_id`,`contest_problem_initial_final`,`id`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY `contest_round_id_user_id` "
"(`contest_round_id`,`user_id`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `contest_round_id_user_id_type` "
"(`contest_round_id`,`user_id`,`type`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_round_id_user_id_contest_problem_final` "
"(`contest_round_id`,`user_id`,`contest_problem_final`,`id`)"
);
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_round_id_user_id_contest_problem_initial_final` "
"(`contest_round_id`,`user_id`,`contest_problem_initial_final`,`id`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY `contest_problem_id_type` "
"(`contest_problem_id`,`type`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `contest_problem_id_contest_problem_final` "
"(`contest_problem_id`,`contest_problem_final`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_problem_id_contest_problem_initial_final` "
"(`contest_problem_id`,`contest_problem_initial_final`,`id`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY `contest_problem_id_user_id` "
"(`contest_problem_id`,`user_id`,`id`)");
mysql.execute("ALTER TABLE submissions ADD KEY `contest_problem_id_user_id_type` "
"(`contest_problem_id`,`user_id`,`type`,`id`)");
mysql.execute(
"ALTER TABLE submissions ADD KEY `contest_problem_id_user_id_contest_problem_final` "
"(`contest_problem_id`,`user_id`,`contest_problem_final`)"
);
mysql.execute("ALTER TABLE submissions ADD KEY "
"`contest_problem_id_user_id_contest_problem_initial_final` "
"(`contest_problem_id`,`user_id`,`contest_problem_initial_final`)");
stmt.res_bind(submission_user_id, submission_problem_id, submission_contest_problem_id);
while (stmt.next()) {
sim::submissions::update_final(
mysql, submission_user_id, submission_problem_id, submission_contest_problem_id
);
}

mysql.update("UNLOCK TABLES");
mysql.execute("RENAME TABLE schema_subversion_0 TO schema_subversion_1");
}

enum class LockKind {
Expand Down

0 comments on commit 6224398

Please sign in to comment.