fix: 代码审查问题修复
- unit_of_work.py: 简化为纯 session 上下文管理器,消除 double-close 风险 - validation.py: 移除未使用的 import,简化 _score_to_1x2 逻辑 - repositories.py: 将 func 导入移到模块顶层 - 更新所有 get_uow() 调用点使用新接口(yield session 而非 uow 对象)
This commit is contained in:
@@ -16,15 +16,14 @@ async def ingest_bzzoiro_route(req: IngestBzzoiroRequest):
|
||||
"""触发 bzzoiro 采集。"""
|
||||
source = get_source("bzzoiro")
|
||||
try:
|
||||
async with get_uow() as uow:
|
||||
async with get_uow() as session:
|
||||
result = await source.ingest(
|
||||
uow.session,
|
||||
session,
|
||||
leagues=req.leagues,
|
||||
date_from=req.date_from,
|
||||
date_to=req.date_to,
|
||||
status=req.status,
|
||||
)
|
||||
await uow.commit()
|
||||
return IngestResponse(**result)
|
||||
except Exception as e:
|
||||
raise HTTPException(500, str(e))
|
||||
@@ -35,9 +34,8 @@ async def ingest_understat_route(req: IngestUnderstatRequest):
|
||||
"""触发 understat xG 回填。"""
|
||||
source = get_source("understat")
|
||||
try:
|
||||
async with get_uow() as uow:
|
||||
result = await source.ingest(uow.session, league=req.league, season=req.season)
|
||||
await uow.commit()
|
||||
async with get_uow() as session:
|
||||
result = await source.ingest(session, league=req.league, season=req.season)
|
||||
return IngestSimpleResponse(**result)
|
||||
except Exception as e:
|
||||
raise HTTPException(500, str(e))
|
||||
@@ -47,9 +45,8 @@ async def ingest_understat_route(req: IngestUnderstatRequest):
|
||||
async def ingest_injuries_route(req: IngestInjuriesRequest):
|
||||
"""触发伤停采集。"""
|
||||
try:
|
||||
async with get_uow() as uow:
|
||||
result = await ingest_injuries(uow.session, date=req.date)
|
||||
await uow.commit()
|
||||
async with get_uow() as session:
|
||||
result = await ingest_injuries(session, date=req.date)
|
||||
return IngestSimpleResponse(**result)
|
||||
except Exception as e:
|
||||
raise HTTPException(500, str(e))
|
||||
|
||||
Reference in New Issue
Block a user