perf(methods): 通过移除不必要的 self 参数优化方法签名
在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
from typing import List, Dict, Any, Optional
|
||||
|
||||
from src.common.logger import get_logger
|
||||
|
||||
logger = get_logger("base_event")
|
||||
@@ -90,8 +91,6 @@ class BaseEvent:
|
||||
self.allowed_subscribers = allowed_subscribers # 记录事件处理器名
|
||||
self.allowed_triggers = allowed_triggers # 记录插件名
|
||||
|
||||
from src.plugin_system.base.base_events_handler import BaseEventHandler
|
||||
|
||||
self.subscribers: List["BaseEventHandler"] = [] # 订阅该事件的事件处理器列表
|
||||
|
||||
self.event_handle_lock = asyncio.Lock()
|
||||
@@ -150,7 +149,8 @@ class BaseEvent:
|
||||
|
||||
return HandlerResultsCollection(processed_results)
|
||||
|
||||
async def _execute_subscriber(self, subscriber, params: dict) -> HandlerResult:
|
||||
@staticmethod
|
||||
async def _execute_subscriber(subscriber, params: dict) -> HandlerResult:
|
||||
"""执行单个订阅者处理器"""
|
||||
try:
|
||||
return await subscriber.execute(params)
|
||||
|
||||
@@ -277,7 +277,8 @@ class PluginBase(ABC):
|
||||
return config_version_field.default
|
||||
return "1.0.0"
|
||||
|
||||
def _get_current_config_version(self, config: Dict[str, Any]) -> str:
|
||||
@staticmethod
|
||||
def _get_current_config_version(config: Dict[str, Any]) -> str:
|
||||
"""从配置文件中获取当前版本号"""
|
||||
if "plugin" in config and "config_version" in config["plugin"]:
|
||||
return str(config["plugin"]["config_version"])
|
||||
|
||||
@@ -149,7 +149,7 @@ class PlusCommand(ABC):
|
||||
Returns:
|
||||
bool: 如果匹配返回True
|
||||
"""
|
||||
return not self.args.is_empty() or self._is_exact_command_call()
|
||||
return not self.args.is_empty or self._is_exact_command_call()
|
||||
|
||||
def _is_exact_command_call(self) -> bool:
|
||||
"""检查是否是精确的命令调用(无参数)"""
|
||||
|
||||
Reference in New Issue
Block a user