fix: 修复注册和上传素材在 await 前后的并发竞态;补充 SQLite 写法说明
Deploy / deploy (build, debian, 22) (push) Canceled after 0s
Deploy / deploy (build, debian, 22) (push) Canceled after 0s
- 注册 / 新建用户 / 批量建用户:先算密码哈希,再同步地查重和插入, 同名并发请求返回 400 而不是撞唯一约束变成 500 - 上传任务素材改用 INSERT ... ON CONFLICT DO UPDATE - CLAUDE.md 补充同步阻塞、行内大文本列、索引、类型差异等注意事项 - 忽略根目录的 db.sqlite3(线上数据备份) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e6a3da14b0
commit
ceba1c68f2
4 files changed
+17
-12
No files matched your search
@@ -96,15 +96,12 @@ for (const kind of ["challenge", "tutorial"] as const) {
|
||||
`tasks/${task.task_type}/${task.display}/${validFilename(name)}`,
|
||||
file,
|
||||
)
|
||||
if (existing) {
|
||||
run(`UPDATE task_taskasset SET file = $file WHERE id = $id`, { file: stored, id: existing.id })
|
||||
} else {
|
||||
run(`INSERT INTO task_taskasset (name, file, task_id) VALUES ($name, $file, $task_id)`, {
|
||||
name,
|
||||
file: stored,
|
||||
task_id: task.id,
|
||||
})
|
||||
}
|
||||
// 上面 await 期间可能有同名上传先写入了,用 upsert 而不是按 existing 选 INSERT / UPDATE
|
||||
run(
|
||||
`INSERT INTO task_taskasset (name, file, task_id) VALUES ($name, $file, $task_id)
|
||||
ON CONFLICT (task_id, name) DO UPDATE SET file = excluded.file`,
|
||||
{ name, file: stored, task_id: task.id },
|
||||
)
|
||||
return c.json(assetOut({ name, file: stored }))
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user