migrate: fix HUSTOJ existed problems#1009
Conversation
WalkthroughThe migration script in Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/migrate/scripts/hustoj.tsOops! Something went wrong! :( ESLint: 9.30.1 Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@hydrooj/eslint-config' imported from /eslint.config.mjs 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
packages/migrate/scripts/hustoj.ts (2)
240-245: Same off-by-one in problem progress output.
pageId % 10 === 0logs before any page is processed. Use(pageId + 1) % 10 === 0.
293-297: Ditto for contest progress output.Adjust the modulus check to avoid the 0th-iteration log.
🧹 Nitpick comments (2)
packages/migrate/scripts/hustoj.ts (2)
142-146: Off-by-one in progress reporting condition.
uidx % 100 === 0fires on the very first iteration (uidx = 0) and prints “1 / N (1 %)”.
Use(uidx + 1) % 100 === 0(or start the counter at 1) to avoid the premature message:-if (uidx % 100 === 0) { +if ((uidx + 1) % 100 === 0) {Apply the same fix to the problem/contest/record loops below.
323-328: Mixednumber/BigIntarithmetic – definestepas BigInt for clarity.
stepis anumber, but is combined withBigIntin expressions (BigInt(step), template literals, etc.).
Define once:-const step = 50; +const step = 50n; // BigIntand drop the repeated casts. This removes implicit conversions and keeps the math type-safe.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/migrate/scripts/hustoj.ts(6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/migrate/scripts/hustoj.ts (1)
packages/hydrooj/src/script/problemStat.ts (1)
udoc(9-52)
🔇 Additional comments (1)
packages/migrate/scripts/hustoj.ts (1)
137-139: Existing users never getnAccept/nSubmitupdated.When a duplicate user is detected earlier the branch skips this
setUserInDomaincall, leaving their stats at whatever default existed.
If the objective is to reflect accurate acceptance counts for all users, updatenAccept&nSubmitin the duplicate branch as well.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/migrate/scripts/hustoj.ts (2)
142-147: Progress log fires on the very first item
uidx % 100 === 0(and similar checks below) logs at index 0, 100, 200…
If you only want every full 100 processed, use(uidx + 1) % 100 === 0or start loop counter at 1.
322-327: BigInt / Number mixing inLIMITclause
LIMIT ${pageId * BigInt(step)}, ${step}concatenates a BigInt and a Number.
While string interpolation works, JS forbids arithmetic mixing—this is safe here but brittle. Consider:const offset = Number(pageId) * step; const limit = step; ... LIMIT ${offset}, ${limit}Keeps types consistent and avoids accidental
BigIntleaks elsewhere.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/migrate/scripts/hustoj.ts(6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/migrate/scripts/hustoj.ts (1)
packages/hydrooj/src/script/problemStat.ts (1)
udoc(9-52)
🔇 Additional comments (1)
packages/migrate/scripts/hustoj.ts (1)
285-288: Contest password is stored verbatim
{ _code: tdoc.password }persists the raw password.
Confirm that Hydro’sContestModelhashes/encodes this field onadd; otherwise store a hash to avoid leaking plain credentials in the DB backup.
| school: udoc.school || '', | ||
| nSubmit: udoc.submit, | ||
| nAccept: 0, | ||
| nAccept: userAcMap[udoc.user_id] || 0, |
There was a problem hiding this comment.
This can be re-calculated by daily task, so there's no need to ensure it's correct
Fix:
New feature:
Summary by CodeRabbit
Enhancements
Bug Fixes