fix: auto-fix code issues (cron)

- 修复隐式 Optional 类型注解 (RUF013)
- 修复不必要的赋值后返回 (RET504)
- 优化列表推导式 (PERF401)
- 修复未使用的参数 (ARG002)
- 清理重复导入
- 优化异常处理
This commit is contained in:
AutoFix Bot
2026-03-03 21:11:47 +08:00
parent d17a58ceae
commit 259f2c90d0
36 changed files with 1651 additions and 863 deletions

View File

@@ -444,7 +444,8 @@ class CacheManager:
"memory_size_bytes": self.current_memory_size,
"max_memory_size_bytes": self.max_memory_size,
"memory_usage_percent": round(
self.current_memory_size / self.max_memory_size * 100, 2,
self.current_memory_size / self.max_memory_size * 100,
2,
),
"cache_entries": len(self.memory_cache),
},
@@ -548,11 +549,13 @@ class CacheManager:
# 预热项目知识库摘要
entity_count = conn.execute(
"SELECT COUNT(*) FROM entities WHERE project_id = ?", (project_id,),
"SELECT COUNT(*) FROM entities WHERE project_id = ?",
(project_id,),
).fetchone()[0]
relation_count = conn.execute(
"SELECT COUNT(*) FROM entity_relations WHERE project_id = ?", (project_id,),
"SELECT COUNT(*) FROM entity_relations WHERE project_id = ?",
(project_id,),
).fetchone()[0]
summary = {
@@ -757,11 +760,13 @@ class DatabaseSharding:
source_conn.row_factory = sqlite3.Row
entities = source_conn.execute(
"SELECT * FROM entities WHERE project_id = ?", (project_id,),
"SELECT * FROM entities WHERE project_id = ?",
(project_id,),
).fetchall()
relations = source_conn.execute(
"SELECT * FROM entity_relations WHERE project_id = ?", (project_id,),
"SELECT * FROM entity_relations WHERE project_id = ?",
(project_id,),
).fetchall()
source_conn.close()
@@ -1061,7 +1066,9 @@ class TaskQueue:
task.status = "retrying"
# 延迟重试
threading.Timer(
10 * task.retry_count, self._execute_task, args=(task_id,),
10 * task.retry_count,
self._execute_task,
args=(task_id,),
).start()
else:
task.status = "failed"
@@ -1163,7 +1170,10 @@ class TaskQueue:
return self.tasks.get(task_id)
def list_tasks(
self, status: str | None = None, task_type: str | None = None, limit: int = 100,
self,
status: str | None = None,
task_type: str | None = None,
limit: int = 100,
) -> list[TaskInfo]:
"""列出任务"""
conn = sqlite3.connect(self.db_path)
@@ -1635,7 +1645,7 @@ def cached(
cache_key = key_func(*args, **kwargs)
else:
# 默认使用函数名和参数哈希
key_data = f"{func.__name__}:{str(args)}:{str(kwargs)}"
key_data = f"{func.__name__}:{args!s}:{kwargs!s}"
cache_key = f"{key_prefix}:{hashlib.md5(key_data.encode()).hexdigest()[:16]}"
# 尝试从缓存获取
@@ -1754,12 +1764,16 @@ _performance_manager = None
def get_performance_manager(
db_path: str = "insightflow.db", redis_url: str | None = None, enable_sharding: bool = False,
db_path: str = "insightflow.db",
redis_url: str | None = None,
enable_sharding: bool = False,
) -> PerformanceManager:
"""获取性能管理器单例"""
global _performance_manager
if _performance_manager is None:
_performance_manager = PerformanceManager(
db_path=db_path, redis_url=redis_url, enable_sharding=enable_sharding,
db_path=db_path,
redis_url=redis_url,
enable_sharding=enable_sharding,
)
return _performance_manager