fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -221,10 +221,10 @@ class CacheManager:
|
||||
""")
|
||||
|
||||
conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_metrics_type ON performance_metrics(metric_type)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_metrics_type ON performance_metrics(metric_type)",
|
||||
)
|
||||
conn.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_metrics_time ON performance_metrics(timestamp)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_metrics_time ON performance_metrics(timestamp)",
|
||||
)
|
||||
|
||||
conn.commit()
|
||||
@@ -444,10 +444,10 @@ 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),
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
return stats
|
||||
@@ -548,11 +548,11 @@ 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 +757,11 @@ 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()
|
||||
@@ -865,7 +865,7 @@ class DatabaseSharding:
|
||||
"is_active": shard_info.is_active,
|
||||
"created_at": shard_info.created_at,
|
||||
"last_accessed": shard_info.last_accessed,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
return stats
|
||||
@@ -1061,7 +1061,7 @@ 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 +1163,7 @@ 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)
|
||||
@@ -1209,7 +1209,7 @@ class TaskQueue:
|
||||
error_message=row["error_message"],
|
||||
retry_count=row["retry_count"],
|
||||
max_retries=row["max_retries"],
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
return tasks
|
||||
@@ -1754,12 +1754,12 @@ _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
|
||||
|
||||
Reference in New Issue
Block a user