diff --git a/packages/migrate/scripts/hustoj.ts b/packages/migrate/scripts/hustoj.ts index fce05ef7c..b1fca67d8 100644 --- a/packages/migrate/scripts/hustoj.ts +++ b/packages/migrate/scripts/hustoj.ts @@ -100,7 +100,8 @@ export async function run({ const udocs = await query('SELECT * FROM `users`'); const precheck = await UserModel.getMulti({ unameLower: { $in: udocs.map((u) => u.user_id.toLowerCase()) } }).toArray(); if (precheck.length) throw new Error(`Conflict username: ${precheck.map((u) => u.unameLower).join(', ')}`); - for (const udoc of udocs) { + for (let uidx = 0; uidx < udocs.length; uidx += 1) { + const udoc = udocs[uidx]; if (randomMail) delete udoc.email; let current = await UserModel.getByEmail(domainId, udoc.email || `${udoc.user_id}@hustoj.local`); current ||= await UserModel.getByUname(domainId, udoc.user_id); @@ -128,6 +129,13 @@ export async function run({ nAccept: 0, }); } + + if (uidx % 100 === 0) { + const progress = Math.round(((uidx + 1) / udocs.length) * 100); + report({ + message: `user finished ${uidx + 1} / ${udocs.length} (${progress}%)`, + }); + } } const admins = await query("SELECT * FROM `privilege` WHERE `rightstr` = 'administrator'"); @@ -220,6 +228,12 @@ target: ybtbas/${+pdoc.id - 3000} await SolutionModel.add(domainId, pidMap[pdoc.problem_id], 1, md); } } + if (pageId % 10 === 0) { + const progress = Math.round(((pageId * step) / pcount) * 100); + report({ + message: `problem finished ${pageId * step} / ${pcount} (${progress}%)`, + }); + } } if (remoteUsed) { MessageModel.sendNotification(`您导入的数据中使用了一本通编程启蒙远端测试题目。 @@ -245,8 +259,9 @@ hydrooj install https://hydro.ac/hydroac-client.zip */ const tidMap: Record = {}; const tdocs = await query('SELECT * FROM `contest`'); - for (const tdoc of tdocs) { - const pdocs = await query(`SELECT * FROM \`contest_problem\` WHERE \`contest_id\` = ${tdoc.contest_id}`); + for (let tidx = 0; tidx < tdocs.length; tidx += 1) { + const tdoc = tdocs[tidx]; + const pdocs = await query(`SELECT * FROM \`contest_problem\` WHERE \`contest_id\` = ${tdoc.contest_id} ORDER BY \`num\` ASC`); const pids = pdocs.map((i) => pidMap[i.problem_id]).filter((i) => i); const files = {}; let description = tdoc.description; @@ -260,11 +275,18 @@ hydrooj install https://hydro.ac/hydroac-client.zip const tid = await ContestModel.add( domainId, tdoc.title, description || 'Description', adminUids[0], contestType, tdoc.start_time, endAt, pids, true, - { _code: password }, + { _code: tdoc.password }, ); tidMap[tdoc.contest_id] = tid.toHexString(); await Promise.all(Object.keys(files).map((filename) => addContestFile(domainId, tid, filename, files[filename]))); if (Object.keys(files).length) report({ message: `move ${Object.keys(files).length} file for contest ${tidMap[tdoc.contest_id]}` }); + + if (tidx % 100 === 0) { + const progress = Math.round(((tidx + 1) / tdocs.length) * 100); + report({ + message: `contest finished ${tidx + 1} / ${tdocs.length} (${progress}%)`, + }); + } } report({ message: 'contest finished' }); /* @@ -288,11 +310,12 @@ hydrooj install https://hydro.ac/hydroac-client.zip lint_error int N ??? judger char(16) N 判题机 */ - const [{ 'count(*)': _rcount }] = await query('SELECT count(*) FROM `solution`'); + // 测试运行 problem_id=0 导致非比赛的提交无法确定属于哪个题目,因此跳过测试运行 + const [{ 'count(*)': _rcount }] = await query('SELECT count(*) FROM `solution` WHERE `problem_id` > 0'); const rcount = BigInt(_rcount); const rpageCount = rcount / BigInt(step) + (rcount % BigInt(step) === 0n ? 0n : 1n); for (let pageId = 0n; pageId < rpageCount; pageId++) { - const rdocs = await query(`SELECT * FROM \`solution\` LIMIT ${pageId * BigInt(step)}, ${step}`); + const rdocs = await query(`SELECT * FROM \`solution\` WHERE \`problem_id\` > 0 LIMIT ${pageId * BigInt(step)}, ${step}`); for (const rdoc of rdocs) { const data: RecordDoc = { status: statusMap[rdoc.result] || 0,