mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 12:52:26 +00:00
refactor: 完成项目大规模代码重构与依赖清理
这是一次综合性的重构更新,包含以下主要变更: 1. 升级Python版本到3.12,更新依赖配置 2. 替换旧的.j2模板为.jinja2格式,新增代码生成模板 3. 重构权限过滤策略,更新权限枚举与模型配置 4. 移除Prefect依赖,替换为自研拓扑并行执行引擎 5. 重构认证与上下文管理,拆分租户/请求上下文 6. 简化响应模型、CRUD与服务层代码 7. 清理废弃的支付网关模块,重构订单定时任务 8. 更新在线用户、监控等模块的接口与路由 9. 优化邮件模板与工具类,新增邮件模板文件 10. 修复数据库会话配置与类型提示
This commit is contained in:
+16
-92
@@ -7,21 +7,10 @@ from .schema import CacheInfoSchema, CacheMonitorSchema
|
||||
|
||||
|
||||
class CacheService:
|
||||
"""
|
||||
缓存监控模块服务层
|
||||
"""
|
||||
"""缓存监控模块服务层"""
|
||||
|
||||
@classmethod
|
||||
async def get_cache_monitor_statistical_info_service(cls, redis: Redis) -> CacheMonitorSchema:
|
||||
"""
|
||||
获取缓存监控信息。
|
||||
|
||||
参数:
|
||||
- redis (Redis): Redis 对象。
|
||||
|
||||
返回:
|
||||
- dict: 缓存监控信息字典。
|
||||
"""
|
||||
@staticmethod
|
||||
async def get_monitor_statistical_info(redis: Redis) -> CacheMonitorSchema:
|
||||
info = await RedisCURD(redis).info()
|
||||
db_size = await RedisCURD(redis).db_size()
|
||||
command_stats_dict = await RedisCURD(redis).commandstats()
|
||||
@@ -29,14 +18,8 @@ class CacheService:
|
||||
command_stats = [{"name": key.split("_")[1], "value": str(value.get("calls"))} for key, value in command_stats_dict.items()]
|
||||
return CacheMonitorSchema(command_stats=command_stats, db_size=db_size, info=info)
|
||||
|
||||
@classmethod
|
||||
async def get_cache_monitor_cache_name_service(cls) -> list[CacheInfoSchema]:
|
||||
"""
|
||||
获取缓存名称列表信息。
|
||||
|
||||
返回:
|
||||
- list: 缓存名称列表信息。
|
||||
"""
|
||||
@staticmethod
|
||||
async def get_monitor_cache_names() -> list[CacheInfoSchema]:
|
||||
return [
|
||||
CacheInfoSchema(
|
||||
cache_key="",
|
||||
@@ -47,38 +30,14 @@ class CacheService:
|
||||
for key_config in RedisInitKeyConfig
|
||||
]
|
||||
|
||||
@classmethod
|
||||
async def get_cache_monitor_cache_key_service(cls, redis: Redis, cache_name: str) -> list:
|
||||
"""
|
||||
获取缓存键名列表信息。
|
||||
|
||||
参数:
|
||||
- redis (Redis): Redis 对象。
|
||||
- cache_name (str): 缓存名称。
|
||||
|
||||
返回:
|
||||
- list: 缓存键名列表信息。
|
||||
"""
|
||||
@staticmethod
|
||||
async def get_monitor_cache_keys(redis: Redis, cache_name: str) -> list:
|
||||
cache_keys = await RedisCURD(redis).get_keys(f"{cache_name}*")
|
||||
cache_key_list = [key.split(":", 1)[1] for key in cache_keys if key.startswith(f"{cache_name}:")]
|
||||
return [key.split(":", 1)[1] for key in cache_keys if key.startswith(f"{cache_name}:")]
|
||||
|
||||
return cache_key_list
|
||||
|
||||
@classmethod
|
||||
async def get_cache_monitor_cache_value_service(cls, redis: Redis, cache_name: str, cache_key: str) -> CacheInfoSchema:
|
||||
"""
|
||||
获取缓存内容信息。
|
||||
|
||||
参数:
|
||||
- redis (Redis): Redis 对象。
|
||||
- cache_name (str): 缓存名称。
|
||||
- cache_key (str): 缓存键名。
|
||||
|
||||
返回:
|
||||
- dict: 缓存内容信息字典。
|
||||
"""
|
||||
@staticmethod
|
||||
async def get_monitor_cache_value(redis: Redis, cache_name: str, cache_key: str) -> CacheInfoSchema:
|
||||
cache_value = await RedisCURD(redis).get(f"{cache_name}:{cache_key}")
|
||||
|
||||
return CacheInfoSchema(
|
||||
cache_key=cache_key,
|
||||
cache_name=cache_name,
|
||||
@@ -86,58 +45,23 @@ class CacheService:
|
||||
remark="",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def clear_cache_monitor_cache_name_service(cls, redis: Redis, cache_name: str) -> bool:
|
||||
"""
|
||||
清除指定缓存名称对应的所有键值。
|
||||
|
||||
参数:
|
||||
- redis (Redis): Redis 对象。
|
||||
- cache_name (str): 缓存名称。
|
||||
|
||||
返回:
|
||||
- bool: 是否清理成功。
|
||||
"""
|
||||
@staticmethod
|
||||
async def clear_monitor_cache_by_name(redis: Redis, cache_name: str) -> bool:
|
||||
cache_keys = await RedisCURD(redis).get_keys(f"{cache_name}*")
|
||||
if cache_keys:
|
||||
await RedisCURD(redis).delete(*cache_keys)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
async def clear_cache_monitor_cache_key_service(cls, redis: Redis, cache_key: str) -> bool:
|
||||
"""
|
||||
清除匹配指定键名的所有键值。
|
||||
|
||||
参数:
|
||||
- redis (Redis): Redis 对象。
|
||||
- cache_key (str): 缓存键名。
|
||||
|
||||
返回:
|
||||
- bool: 是否清理成功。
|
||||
"""
|
||||
@staticmethod
|
||||
async def clear_monitor_cache_by_key(redis: Redis, cache_key: str) -> bool:
|
||||
cache_keys = await RedisCURD(redis).get_keys(f"*{cache_key}")
|
||||
if cache_keys:
|
||||
await RedisCURD(redis).delete(*cache_keys)
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
async def clear_cache_monitor_all_service(cls, redis: Redis) -> bool:
|
||||
"""
|
||||
清除所有缓存。
|
||||
|
||||
参数:
|
||||
- redis (Redis): Redis 对象。
|
||||
|
||||
返回:
|
||||
- bool: 是否清理成功。
|
||||
"""
|
||||
@staticmethod
|
||||
async def clear_monitor_cache_all(redis: Redis) -> bool:
|
||||
cache_keys = await RedisCURD(redis).get_keys()
|
||||
if cache_keys:
|
||||
await RedisCURD(redis).delete(*cache_keys)
|
||||
|
||||
return True
|
||||
|
||||
# 避免清除所有的缓存,而采用上面的方式,只清除本系统内指定的所有缓存
|
||||
# return await RedisCURD(redis).clear()
|
||||
|
||||
Reference in New Issue
Block a user