refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.db import transactional
|
||||
from app.features.user.models import User
|
||||
|
||||
|
||||
@@ -37,17 +38,21 @@ async def apply_extracted_profile(user: User, extracted: dict, db: AsyncSession)
|
||||
"""将提取到的资料信息保存到用户模型"""
|
||||
changed = False
|
||||
if "birth_year" in extracted and not user.birth_year:
|
||||
user.birth_year = extracted["birth_year"]
|
||||
changed = True
|
||||
if "birth_place" in extracted and not user.birth_place:
|
||||
user.birth_place = extracted["birth_place"]
|
||||
changed = True
|
||||
if "grew_up_place" in extracted and not user.grew_up_place:
|
||||
user.grew_up_place = extracted["grew_up_place"]
|
||||
changed = True
|
||||
if "occupation" in extracted and not user.occupation:
|
||||
user.occupation = extracted["occupation"]
|
||||
changed = True
|
||||
if changed:
|
||||
await db.commit()
|
||||
async with transactional(db):
|
||||
if "birth_year" in extracted and not user.birth_year:
|
||||
user.birth_year = extracted["birth_year"]
|
||||
if "birth_place" in extracted and not user.birth_place:
|
||||
user.birth_place = extracted["birth_place"]
|
||||
if "grew_up_place" in extracted and not user.grew_up_place:
|
||||
user.grew_up_place = extracted["grew_up_place"]
|
||||
if "occupation" in extracted and not user.occupation:
|
||||
user.occupation = extracted["occupation"]
|
||||
await db.refresh(user)
|
||||
|
||||
Reference in New Issue
Block a user