fix+perf: SQLite连接busy_timeout修复并发锁/静态版本号缓存/删除资产批量清理/安全检查最新记录子查询修正/AI余额与SSL探测并发化/密钥常量时间比较
This commit is contained in:
@@ -15,19 +15,26 @@ DEFAULT_WEIGHT = 20
|
||||
|
||||
|
||||
def latest_checks(session: Session, asset_id: int) -> list:
|
||||
"""取每个检查项的最新一条"""
|
||||
stmt = (
|
||||
select(SecurityCheck)
|
||||
"""取每个检查项的最新一条
|
||||
|
||||
用 GROUP BY max(ts) 子查询精确取每项最新记录:若用 limit(50) 后去重,
|
||||
当某个检查项连续上报超过 50 次时会把其他项的最新记录挤出,导致评分失真。
|
||||
"""
|
||||
latest_ts = (
|
||||
select(
|
||||
SecurityCheck.check_item,
|
||||
func.max(SecurityCheck.ts).label("max_ts"),
|
||||
)
|
||||
.where(SecurityCheck.asset_id == asset_id)
|
||||
.order_by(SecurityCheck.ts.desc())
|
||||
.limit(50)
|
||||
.group_by(SecurityCheck.check_item)
|
||||
.subquery()
|
||||
)
|
||||
checks = session.exec(stmt).all()
|
||||
latest = {}
|
||||
for check in checks:
|
||||
if check.check_item not in latest:
|
||||
latest[check.check_item] = check
|
||||
return list(latest.values())
|
||||
stmt = select(SecurityCheck).where(SecurityCheck.asset_id == asset_id).join(
|
||||
latest_ts,
|
||||
(SecurityCheck.check_item == latest_ts.c.check_item)
|
||||
& (SecurityCheck.ts == latest_ts.c.max_ts),
|
||||
)
|
||||
return list(session.exec(stmt).all())
|
||||
|
||||
|
||||
def compute_security_score(checks: list):
|
||||
|
||||
Reference in New Issue
Block a user