mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-28 16:20:56 +08:00
refactor: replace legacy auth checker with optimized auth checker for improved performance
This commit is contained in:
@@ -16,17 +16,11 @@
|
||||
"""
|
||||
|
||||
import nonebot
|
||||
from nonebot.adapters import Bot, Event
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.message import run_preprocessor
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_uninfo import Uninfo
|
||||
|
||||
from zhenxun.services.auth_snapshot import (
|
||||
AuthSnapshotService,
|
||||
PluginSnapshotService,
|
||||
)
|
||||
from zhenxun.services.auth_snapshot.checker import optimized_auth_checker
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.manager.priority_manager import PriorityLifecycle
|
||||
|
||||
@@ -49,19 +43,3 @@ async def _cleanup_cache():
|
||||
AuthSnapshotService.clear_all_cache()
|
||||
PluginSnapshotService.clear_all_cache()
|
||||
logger.info("快照缓存已清理", "auth_checker_v2")
|
||||
|
||||
|
||||
# 权限检查前处理器
|
||||
@run_preprocessor
|
||||
async def auth_check_v2(
|
||||
matcher: Matcher,
|
||||
event: Event,
|
||||
bot: Bot,
|
||||
session: Uninfo,
|
||||
message: UniMsg,
|
||||
):
|
||||
"""优化后的权限检查
|
||||
|
||||
使用预聚合的权限快照进行检查,大幅减少数据库/缓存查询次数
|
||||
"""
|
||||
await optimized_auth_checker.check(matcher, event, bot, session, message)
|
||||
|
||||
@@ -6,23 +6,25 @@ from nonebot.message import run_postprocessor, run_preprocessor
|
||||
from nonebot_plugin_alconna import UniMsg
|
||||
from nonebot_plugin_uninfo import Uninfo
|
||||
|
||||
from zhenxun.services.auth_snapshot.checker import optimized_auth_checker
|
||||
from zhenxun.services.log import logger
|
||||
|
||||
from .auth.config import LOGGER_COMMAND
|
||||
from .auth_checker import LimitManager, _auth_checker
|
||||
from .auth_checker import LimitManager
|
||||
|
||||
|
||||
# # 权限检测
|
||||
@run_preprocessor
|
||||
async def _(matcher: Matcher, event: Event, bot: Bot, session: Uninfo, message: UniMsg):
|
||||
start_time = time.time()
|
||||
await _auth_checker.check(
|
||||
matcher,
|
||||
event,
|
||||
bot,
|
||||
session,
|
||||
message,
|
||||
)
|
||||
# await _auth_checker.check(
|
||||
# matcher,
|
||||
# event,
|
||||
# bot,
|
||||
# session,
|
||||
# message,
|
||||
# )
|
||||
await optimized_auth_checker.check(matcher, event, bot, session, message)
|
||||
logger.debug(f"权限检测耗时:{time.time() - start_time}秒", LOGGER_COMMAND)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user