fix: 数据库与数据管线审查问题修复 (6 P1 + 5 P2) #3

Merged
shangfangjian merged 1 commits from fix/db-pipeline-review-issues into main 2026-09-16 03:14:37 +08:00
Collaborator

概要

修复数据库与数据管线相关的 6 个 P1 + 5 个 P2 审查发现。

P1 修复

# 文件 修改
P1-1 context_builder.py build_context 共享 session,切片函数传 db 参数,回测 20 场并发连接需求从 100+ 降至每场 1 个
P1-2 bzzoiro.py 预加载改为按 raw_events 日期范围 ±30 天按需加载,避免多赛季内存溢出
P1-3 understat.py 批量查询球队+比赛,从 1140 次 DB 往返降到 3 次
P1-4 injuries.py 批量幂等检查 + 分批 flush,IntegrityError 逐条回退而非整批回滚
P1-5 predict.py 删除 threading.Lock,dict 操作原子无需同步锁
P1-6 models.py + 迁移 添加 (match_id, provider, model) 唯一约束

P2 修复

# 文件 修改
P2-1 unit_of_work.py get_uow 返回类型改为 AsyncIterator[AsyncSession]
P2-2 normalize.py _parse_date 失败时 warning 记录被丢弃的原始值
P2-3 repositories.py find_by_teams_and_date 改用 match_date_date 等值匹配,避免 func.date() 索引失效
P2-4 migration 0006 幽灵列 cutoff_at 已删除(已有迁移)
P2-5 migration 0007 injuries 约束命名对齐 ORM

新增迁移

  • 0007_injuries_constraint_naming_align.py — 约束命名对齐
  • 0007_predictions_unique_constraint.py — 唯一约束 + 重复数据清理

测试建议

  • 运行 alembic upgrade head 应用新迁移
  • 20 场并发回测压测验证连接池稳定性
## 概要 修复数据库与数据管线相关的 6 个 P1 + 5 个 P2 审查发现。 ### P1 修复 | # | 文件 | 修改 | |---|---|---| | P1-1 | context_builder.py | build_context 共享 session,切片函数传 db 参数,回测 20 场并发连接需求从 100+ 降至每场 1 个 | | P1-2 | bzzoiro.py | 预加载改为按 raw_events 日期范围 ±30 天按需加载,避免多赛季内存溢出 | | P1-3 | understat.py | 批量查询球队+比赛,从 1140 次 DB 往返降到 3 次 | | P1-4 | injuries.py | 批量幂等检查 + 分批 flush,IntegrityError 逐条回退而非整批回滚 | | P1-5 | predict.py | 删除 threading.Lock,dict 操作原子无需同步锁 | | P1-6 | models.py + 迁移 | 添加 (match_id, provider, model) 唯一约束 | ### P2 修复 | # | 文件 | 修改 | |---|---|---| | P2-1 | unit_of_work.py | get_uow 返回类型改为 AsyncIterator[AsyncSession] | | P2-2 | normalize.py | _parse_date 失败时 warning 记录被丢弃的原始值 | | P2-3 | repositories.py | find_by_teams_and_date 改用 match_date_date 等值匹配,避免 func.date() 索引失效 | | P2-4 | migration 0006 | 幽灵列 cutoff_at 已删除(已有迁移) | | P2-5 | migration 0007 | injuries 约束命名对齐 ORM | ### 新增迁移 - `0007_injuries_constraint_naming_align.py` — 约束命名对齐 - `0007_predictions_unique_constraint.py` — 唯一约束 + 重复数据清理 ## 测试建议 - 运行 `alembic upgrade head` 应用新迁移 - 20 场并发回测压测验证连接池稳定性
bilidili added 1 commit 2026-09-16 03:13:10 +08:00
P1-1 [context_builder] build_context 共享 session,切片函数传 db 参数,
        回测 20 场并发连接需求从 100+ 降至每场 1 个
P1-2 [bzzoiro] 预加载改为按 raw_events 日期范围 ±30 天按需加载
P1-3 [understat] 批量查询球队 + 比赛,从 1140 次往返降到 3 次
P1-4 [injuries] 批量幂等检查 + 分批 flush,IntegrityError 逐条回退
P1-5 [predict] 删除 threading.Lock,dict 操作原子无需同步锁
P1-6 [models] 添加 (match_id, provider, model) 唯一约束 + 迁移

P2-1 [unit_of_work] get_uow 返回类型改为 AsyncIterator[AsyncSession]
P2-2 [normalize] _parse_date 失败时记录 warning 避免静默丢数据
P2-3 [repositories] find_by_teams_and_date 改用 match_date_date 等值匹配
P2-4 [migration] 幽灵列 cutoff_at 已在 0006 迁移删除(已有)
P2-5 [migration] injuries 约束命名对齐 ORM,UniqueConstraint → 唯一索引
shangfangjian merged commit e89ab1a0c9 into main 2026-09-16 03:14:37 +08:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shangfangjian/Profeto#3