mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-14 21:52:56 +08:00
Update utils.py
This commit is contained in:
parent
7058850444
commit
11ef9c4382
@ -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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user