fix(database): 修复decorators循环导入问题
在cached装饰器中延迟导入get_cache,避免以下循环依赖: decorators -> optimization.get_cache -> batch_scheduler -> session -> engine -> utils.exceptions 这个修复确保了所有装饰器可以正常导入和使用
This commit is contained in:
@@ -14,7 +14,6 @@ from typing import Any, Awaitable, Callable, Optional, TypeVar
|
|||||||
|
|
||||||
from sqlalchemy.exc import DBAPIError, OperationalError, TimeoutError as SQLTimeoutError
|
from sqlalchemy.exc import DBAPIError, OperationalError, TimeoutError as SQLTimeoutError
|
||||||
|
|
||||||
from src.common.database.optimization import get_cache
|
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
|
|
||||||
logger = get_logger("database.decorators")
|
logger = get_logger("database.decorators")
|
||||||
@@ -130,6 +129,9 @@ def cached(
|
|||||||
def decorator(func: Callable[..., T]) -> Callable[..., T]:
|
def decorator(func: Callable[..., T]) -> Callable[..., T]:
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
async def wrapper(*args: Any, **kwargs: Any) -> T:
|
async def wrapper(*args: Any, **kwargs: Any) -> T:
|
||||||
|
# 延迟导入避免循环依赖
|
||||||
|
from src.common.database.optimization import get_cache
|
||||||
|
|
||||||
# 生成缓存键
|
# 生成缓存键
|
||||||
cache_key_parts = [key_prefix or func.__name__]
|
cache_key_parts = [key_prefix or func.__name__]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user