Django 多个 worker 内存占用 1-2 GB,换成 Bun 单进程后约 25 MB, 同时去掉 Postgres 和 Redis,只剩 Caddy + Bun 两个容器。 - server/:Hono + bun:sqlite + Bun 原生 WebSocket,接口与原 django-ninja 保持兼容;表结构、时间/UUID 存储格式、密码哈希与 Django 一致,旧数据可直接使用 - 评分加权、贝叶斯平滑、成绩册的计算结果与原实现逐位一致(复刻 Python round/sum) - scripts/:Postgres → SQLite 迁移、新建超管、提示词层级标注、重算分数 - 前端:Django Admin 去掉后,用户新建/修改改为页面内弹窗; 非超管的挑战公开按钮置灰 - 权限不足返回 JSON 403(原来是重定向到不存在的登录页) - docker-compose / Caddyfile / dev.sh / CLAUDE.md 更新,删除 AGENTS.md - 服务器切换步骤见 docs/migrate-to-bun.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
/**
|
|
* 重新计算所有被评过分的提交的 score / raw_score / zone(修改评分规则后使用)。
|
|
*
|
|
* bun scripts/recalculate-scores.ts [--dry-run]
|
|
*/
|
|
import { all, get } from "../src/db"
|
|
import { updateSubmissionScore } from "../src/services/score"
|
|
|
|
const rows = all<{ id: string; username: string; title: string; score: number }>(
|
|
`SELECT s.id, u.username, t.title, s.score FROM submission_submission s
|
|
JOIN account_user u ON u.id = s.user_id JOIN task_task t ON t.id = s.task_id
|
|
WHERE EXISTS (SELECT 1 FROM submission_rating r WHERE r.submission_id = s.id)
|
|
ORDER BY s.created DESC`,
|
|
)
|
|
console.log(`找到 ${rows.length} 个被评过分的提交`)
|
|
if (process.argv.includes("--dry-run")) process.exit(0)
|
|
|
|
for (const [i, s] of rows.entries()) {
|
|
updateSubmissionScore(s.id)
|
|
const after = get<{ score: number; zone: string | null }>(
|
|
`SELECT score, zone FROM submission_submission WHERE id = $id`,
|
|
{ id: s.id },
|
|
)!
|
|
console.log(
|
|
`[${i + 1}/${rows.length}] ${s.username}/${s.title}: ${s.score.toFixed(3)} → ${after.score.toFixed(3)} zone=${after.zone}`,
|
|
)
|
|
}
|
|
console.log("完成")
|