refactor(core): 优化权限管理和事件模型
- 重构 AdminManager 和 PermissionManager 以 Redis 为主要数据源 - 为所有事件模型添加 slots=True 提升性能 - 更新文档说明 Mypyc 编译注意事项 - 清理测试和调试文件 - 移动静态资源到 web_static 目录
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
"""
|
||||
通用单例模式基类
|
||||
"""
|
||||
from typing import Any, Optional, Type, TypeVar
|
||||
|
||||
T = TypeVar('T')
|
||||
|
||||
class Singleton:
|
||||
"""
|
||||
@@ -10,18 +13,25 @@ class Singleton:
|
||||
它通过重写 __new__ 方法来确保每个类只有一个实例。
|
||||
同时,它处理了重复初始化的问题,确保 __init__ 方法只在第一次实例化时被调用。
|
||||
"""
|
||||
_instance = None
|
||||
_initialized = False
|
||||
_instance: Optional[Any] = None
|
||||
_initialized: bool = False
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
def __new__(cls: Type[T], *args: Any, **kwargs: Any) -> T:
|
||||
"""
|
||||
创建或返回现有的实例
|
||||
|
||||
Args:
|
||||
*args: 传递给构造函数的位置参数
|
||||
**kwargs: 传递给构造函数的关键字参数
|
||||
|
||||
Returns:
|
||||
T: 单例实例
|
||||
"""
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
确保初始化逻辑只执行一次
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user