🔧 优化数据访问和数据库上下文逻辑,移除不必要的全局变量和日志信息,调整日志级别为调试,提升代码可读性和性能。

This commit is contained in:
HibiKier
2025-08-26 16:28:53 +08:00
parent 90a0ef58b9
commit a89d87a0b4
3 changed files with 2 additions and 42 deletions
-15
View File
@@ -16,9 +16,6 @@ from zhenxun.utils.enum import DbLockType
from .config import LOG_COMMAND, db_model
from .utils import with_db_timeout
total = {}
index = 0
class Model(TortoiseModel):
"""
@@ -224,19 +221,7 @@ class Model(TortoiseModel):
返回:
Self | None: 查询结果,如果不存在返回None
"""
global index, total
try:
if cls.__name__ == "BanConsole":
uid = kwargs.get("user_id")
if uid:
if uid not in total:
total[uid] = CacheRoot.cache_dict(f"DB_TEST_UID_{uid}", 10, int)
total[uid][str(index)] = "1"
index += 1
logger.info(
f"BanConsole 10秒内查询次数 uid: {uid}"
f" 查询次数: {len(total[uid])}"
)
# 先尝试使用 get_or_none 获取单个记录
try:
return await with_db_timeout(