fix+perf: SQLite连接busy_timeout修复并发锁/静态版本号缓存/删除资产批量清理/安全检查最新记录子查询修正/AI余额与SSL探测并发化/密钥常量时间比较
This commit is contained in:
@@ -283,14 +283,19 @@ def delete_asset(session: Session, asset_id: int) -> None:
|
||||
|
||||
|
||||
def _cleanup_metrics_for_asset(asset_id: int) -> None:
|
||||
"""清理 metrics.db 中该资产的 MetricPoint/ServerInfo/SecurityCheck/EventLog"""
|
||||
"""清理 metrics.db 中该资产的 MetricPoint/ServerInfo/SecurityCheck/EventLog
|
||||
|
||||
使用批量 DELETE(而非逐行加载后删除):监控时序数据可能上万行,
|
||||
逐行删除会全部载入内存且产生数万次 ORM 操作。
|
||||
"""
|
||||
from sqlmodel import delete
|
||||
|
||||
from app.database import metrics_engine
|
||||
from app.models.monitor import EventLog, MetricPoint, SecurityCheck, ServerInfo
|
||||
|
||||
with Session(metrics_engine) as ms:
|
||||
for model in (MetricPoint, ServerInfo, SecurityCheck, EventLog):
|
||||
for row in ms.exec(select(model).where(model.asset_id == asset_id)).all():
|
||||
ms.delete(row)
|
||||
ms.exec(delete(model).where(model.asset_id == asset_id))
|
||||
ms.commit()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user