mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor: finish transactional runtime migration
This commit is contained in:
+16
-1
@@ -1,6 +1,6 @@
|
||||
"""从 FastAPI AppState 读取类型化宿主能力。"""
|
||||
|
||||
from collections.abc import AsyncGenerator
|
||||
from collections.abc import AsyncGenerator, Generator
|
||||
from typing import cast
|
||||
|
||||
from fastapi import Depends, Request
|
||||
@@ -39,6 +39,21 @@ def get_api_runtime_config(
|
||||
return runtime.configuration.api()
|
||||
|
||||
|
||||
def get_sync_session(
|
||||
runtime: HostRuntime = Depends(get_host_runtime),
|
||||
) -> Generator[object, None, None]:
|
||||
"""从 HostRuntime 生成请求独占的同步数据库会话。"""
|
||||
yield from runtime.persistence.sync_session()
|
||||
|
||||
|
||||
async def get_async_session(
|
||||
runtime: HostRuntime = Depends(get_host_runtime),
|
||||
) -> AsyncGenerator[object, None]:
|
||||
"""从 HostRuntime 生成请求独占的异步数据库会话。"""
|
||||
async for session in runtime.persistence.async_session():
|
||||
yield session
|
||||
|
||||
|
||||
def resolve_api_runtime_config(value: object) -> ApiRuntimeConfig:
|
||||
"""兼容直接调用 endpoint 的旧入口,并统一返回真实配置快照。"""
|
||||
if isinstance(value, ApiRuntimeConfig):
|
||||
|
||||
Reference in New Issue
Block a user