Update utils.py

This commit is contained in:
HibiKier 2025-10-09 08:42:59 +08:00 committed by GitHub
parent 7058850444
commit 11ef9c4382
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,15 +4,12 @@ import time
from zhenxun.services.log import logger
from ..cache import CacheRoot
from .config import (
DB_TIMEOUT_SECONDS,
LOG_COMMAND,
SLOW_QUERY_THRESHOLD,
)
aaa = CacheRoot.cache_dict("AAA", 10, int)
async def with_db_timeout(
coro,
@ -25,15 +22,9 @@ async def with_db_timeout(
try:
logger.debug(f"开始执行数据库操作: {operation} 来源: {source}")
result = await asyncio.wait_for(coro, timeout=timeout)
aaa[str(random.randint(0, 100000))] = 1
elapsed = time.time() - start_time
if elapsed > SLOW_QUERY_THRESHOLD and operation:
logger.warning(f"慢查询: {operation} 耗时 {elapsed:.3f}s", LOG_COMMAND)
logger.debug(
f"10s内数据库查询次数: {len(aaa)} 开始执行数据库操作: {operation} "
f"来源: {source}, 当次返回数据ID: {getattr(result, 'id', None)}",
LOG_COMMAND,
)
return result
except asyncio.TimeoutError:
if operation: