|
@@ -340,6 +340,9 @@ class PairedImageSaver:
|
|
|
|
|
|
|
|
logger.info(f"[配对保存] 批次完成: {batch.batch_id}")
|
|
logger.info(f"[配对保存] 批次完成: {batch.batch_id}")
|
|
|
|
|
|
|
|
|
|
+ # 清理旧批次
|
|
|
|
|
+ self._cleanup_old_batches()
|
|
|
|
|
+
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
logger.error(f"[配对保存] 异步完成批次失败: {e}")
|
|
logger.error(f"[配对保存] 异步完成批次失败: {e}")
|
|
|
|
|
|
|
@@ -922,8 +925,6 @@ class PairedImageSaver:
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
- from datetime import timedelta
|
|
|
|
|
-
|
|
|
|
|
batch_dirs = sorted(
|
|
batch_dirs = sorted(
|
|
|
[d for d in self.base_dir.iterdir() if d.is_dir() and d.name.startswith('batch_')],
|
|
[d for d in self.base_dir.iterdir() if d.is_dir() and d.name.startswith('batch_')],
|
|
|
key=lambda x: x.stat().st_mtime
|
|
key=lambda x: x.stat().st_mtime
|
|
@@ -934,21 +935,21 @@ class PairedImageSaver:
|
|
|
|
|
|
|
|
now = time.time()
|
|
now = time.time()
|
|
|
to_delete = []
|
|
to_delete = []
|
|
|
- deleted_count = 0
|
|
|
|
|
|
|
|
|
|
for d in batch_dirs:
|
|
for d in batch_dirs:
|
|
|
- # 1. 按数量清理(优先)
|
|
|
|
|
- if len(batch_dirs) - deleted_count > self.max_batches:
|
|
|
|
|
|
|
+ # 按数量清理:超出最大保留数量时删除最旧的
|
|
|
|
|
+ if len(batch_dirs) - len(to_delete) > self.max_batches:
|
|
|
to_delete.append(d)
|
|
to_delete.append(d)
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
- # 2. 按天数清理
|
|
|
|
|
|
|
+ # 按天数清理:超过保留天数时删除
|
|
|
if self.retention_days > 0:
|
|
if self.retention_days > 0:
|
|
|
age_days = (now - d.stat().st_mtime) / 86400
|
|
age_days = (now - d.stat().st_mtime) / 86400
|
|
|
if age_days > self.retention_days:
|
|
if age_days > self.retention_days:
|
|
|
to_delete.append(d)
|
|
to_delete.append(d)
|
|
|
|
|
|
|
|
# 执行删除
|
|
# 执行删除
|
|
|
|
|
+ deleted_count = 0
|
|
|
for d in to_delete:
|
|
for d in to_delete:
|
|
|
import shutil
|
|
import shutil
|
|
|
shutil.rmtree(d)
|
|
shutil.rmtree(d)
|