mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +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 zhenxun.services.log import logger
|
||||||
|
|
||||||
from ..cache import CacheRoot
|
|
||||||
from .config import (
|
from .config import (
|
||||||
DB_TIMEOUT_SECONDS,
|
DB_TIMEOUT_SECONDS,
|
||||||
LOG_COMMAND,
|
LOG_COMMAND,
|
||||||
SLOW_QUERY_THRESHOLD,
|
SLOW_QUERY_THRESHOLD,
|
||||||
)
|
)
|
||||||
|
|
||||||
aaa = CacheRoot.cache_dict("AAA", 10, int)
|
|
||||||
|
|
||||||
|
|
||||||
async def with_db_timeout(
|
async def with_db_timeout(
|
||||||
coro,
|
coro,
|
||||||
@ -25,15 +22,9 @@ async def with_db_timeout(
|
|||||||
try:
|
try:
|
||||||
logger.debug(f"开始执行数据库操作: {operation} 来源: {source}")
|
logger.debug(f"开始执行数据库操作: {operation} 来源: {source}")
|
||||||
result = await asyncio.wait_for(coro, timeout=timeout)
|
result = await asyncio.wait_for(coro, timeout=timeout)
|
||||||
aaa[str(random.randint(0, 100000))] = 1
|
|
||||||
elapsed = time.time() - start_time
|
elapsed = time.time() - start_time
|
||||||
if elapsed > SLOW_QUERY_THRESHOLD and operation:
|
if elapsed > SLOW_QUERY_THRESHOLD and operation:
|
||||||
logger.warning(f"慢查询: {operation} 耗时 {elapsed:.3f}s", LOG_COMMAND)
|
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
|
return result
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
if operation:
|
if operation:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user