perf(score): divide score processing into small parts and make them run in background

resolve #47
This commit is contained in:
MingxuanGame
2025-10-02 14:30:57 +00:00
parent bb1c09f4fd
commit f31056ced3
4 changed files with 389 additions and 169 deletions

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
from collections.abc import AsyncIterator, Callable
from contextlib import asynccontextmanager
from contextvars import ContextVar
from datetime import datetime
import json
@@ -64,8 +65,13 @@ async def get_db():
yield session
def with_db():
return AsyncSession(engine)
@asynccontextmanager
async def with_db():
async with AsyncSession(engine) as session:
try:
yield session
finally:
await session.close()
DBFactory = Callable[[], AsyncIterator[AsyncSession]]