feat: 启动自愈清理孤儿数据与零引用上传文件,表格列宽记忆优化
This commit is contained in:
@@ -1317,6 +1317,26 @@ def _purge_upload_files(names):
|
||||
return gone
|
||||
|
||||
|
||||
def _purge_orphan_uploads():
|
||||
"""启动自愈:uploads 里**零引用**的源文件副本全量对账回收(幂等)。
|
||||
|
||||
2026-10-11 起因:删除路径只清被删会话当时引用的文件,模拟数据工具等渠道留下的
|
||||
孤儿会一直积压(实测 1799 个)。引用口径与 _purge_upload_files 完全一致
|
||||
(sessions.src_name 分段 + batches.x_src_hash),复用它逐个判+删,返回删除个数。"""
|
||||
if not os.path.isdir(UPLOAD_DIR):
|
||||
return 0
|
||||
gone = 0
|
||||
for sub in os.listdir(UPLOAD_DIR):
|
||||
d = os.path.join(UPLOAD_DIR, sub)
|
||||
if not os.path.isdir(d) or len(sub) != 2:
|
||||
continue
|
||||
for f in os.listdir(d):
|
||||
# 只认 <sha256>_<原名> 且桶号=sha 前两位的规矩文件,别的一律不碰
|
||||
if f.startswith(sub) and "_" in f and os.path.isfile(os.path.join(d, f)):
|
||||
gone += _purge_upload_files([f])
|
||||
return gone
|
||||
|
||||
|
||||
def api_sessions():
|
||||
"""最近审核列表:按「项目名称」去重——同名工程只留最近一条(2026-10-07 主人定)
|
||||
|
||||
@@ -3830,6 +3850,14 @@ def run():
|
||||
license_gate.init(DATA_DIR) # 授权门禁:读配置/状态,配了凭据则起心跳线程(内部吞异常)
|
||||
cleanup_sessions() # 启动时清掉超过保留天数的会话(只碰 session.db)
|
||||
sess.dedupe_lme_res() # 2026-10-10:s_lme_res 存量去重自愈(wipe 曾漏这张表,台班组成重复)
|
||||
_n = sess.drop_orphan_rows() # 2026-10-11:s_ 表孤儿行自愈(已删会话的幽灵 sid 残留)
|
||||
if _n > 0:
|
||||
print("[启动自愈] 清掉已删会话的孤儿数据 %d 行" % _n)
|
||||
elif _n < 0:
|
||||
print("[启动自愈] 孤儿数据清理出错(已回滚,不影响启动)")
|
||||
_g = _purge_orphan_uploads() # 2026-10-11:uploads 零引用源文件副本对账回收(幂等)
|
||||
if _g:
|
||||
print("[启动自愈] 回收零引用源文件副本 %d 个" % _g)
|
||||
# 2026-10-11:启动「数据过期」打印已取消(主人定)——打开即自动升级(决策 34)后「需重导」口径不再成立;
|
||||
# stale_batches() 保留:/api/admin/summary 的 stale 字段仍返回,供后续一键批量升级(方案 B)复用。
|
||||
srv = ThreadingHTTPServer(("127.0.0.1", PORT), Handler)
|
||||
|
||||
Reference in New Issue
Block a user