revert: 回退自动删除旧快照的逻辑,保留完整历史版本供人工恢复

This commit is contained in:
mediabot-pt
2026-07-07 13:24:03 +08:00
parent 2c126a6ec5
commit 5777a02823

View File

@@ -134,12 +134,11 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
return null;
}
// 删除旧 draft,保证最新只有一条
snapshotMapper.deleteBySiteIdAndStatus(siteId, "draft");
int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1;
SiteSnapshot snapshot = new SiteSnapshot();
snapshot.setSiteId(siteId);
snapshot.setVersion((latestDraft != null) ? latestDraft.getVersion() + 1 : 1);
snapshot.setVersion(newVersion);
populateSnapshotFields(snapshot, data);
snapshot.setChecksum(checksum);
snapshot.setStatus("draft");
@@ -150,7 +149,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
String bundleJson = toBundleJson(snapshot);
jsonCache.put(draftKey(siteId), bundleJson);
log.info("快照已更新: siteId={}, version={}, checksum={}", siteId, snapshot.getVersion(), checksum.substring(0, 8));
log.info("快照已更新: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8));
return snapshot;
} catch (Exception e) {
log.error("更新快照失败 siteId={}", siteId, e);
@@ -178,12 +177,11 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
return latestDraft;
}
// 删除旧 draft,保证最新只有一条
snapshotMapper.deleteBySiteIdAndStatus(siteId, "draft");
int newVersion = (latestDraft != null) ? latestDraft.getVersion() + 1 : 1;
SiteSnapshot snapshot = new SiteSnapshot();
snapshot.setSiteId(siteId);
snapshot.setVersion((latestDraft != null) ? latestDraft.getVersion() + 1 : 1);
snapshot.setVersion(newVersion);
populateSnapshotFields(snapshot, data);
snapshot.setChecksum(checksum);
snapshot.setStatus("draft");
@@ -194,7 +192,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
String bundleJson = toBundleJson(snapshot);
jsonCache.put(draftKey(siteId), bundleJson);
log.info("预览版已保存: siteId={}, version={}, checksum={}", siteId, snapshot.getVersion(), checksum.substring(0, 8));
log.info("预览版已保存: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8));
return snapshot;
} catch (Exception e) {
log.error("保存预览版失败 siteId={}", siteId, e);
@@ -236,8 +234,7 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
return current;
}
// 先删旧 published,再改当前 draft 为 published(事务保证原子性)
snapshotMapper.deleteBySiteIdAndStatus(siteId, "published");
// 更新状态为 published
draft.setStatus("published");
draft.setPublishedAt(LocalDateTime.now());
snapshotMapper.updateById(draft);