fix: 修复快照两阶段发布方案的缓存一致性和前端问题
1. updateSnapshot() 自动触发生成 draft 后刷新 draft/preview 缓存 2. saveDraft() 同时刷新 previewJsonCache 3. 前端编辑页新增「保存站点」按钮,确保站点基本信息可持久化 4. publishManifest() 兼容 bundle 改用缓存 JSON,避免重复 buildSnapshot
This commit is contained in:
@@ -357,23 +357,18 @@ public class AdminController {
|
||||
// 2. 使用快照服务发布有变更的站点
|
||||
int publishedCount = snapshotService.publishChanged();
|
||||
|
||||
// 3. 兼容:为所有站点生成旧的 bundles/ 路径(从快照读取)
|
||||
// 3. 兼容:为有 published 快照的站点生成旧的 bundles/ 路径
|
||||
int bundleCount = 0;
|
||||
@SuppressWarnings("unchecked")
|
||||
var sites = (List<Map<String, Object>>) manifest.get("sites");
|
||||
for (var site : sites) {
|
||||
String siteId = (String) site.get("siteId");
|
||||
try {
|
||||
var active = snapshotService.getActive(siteId);
|
||||
if (active != null) {
|
||||
// 生成兼容的 bundle JSON 并上传到旧路径
|
||||
Map<String, Object> bundle = snapshotService.buildSnapshot(siteId);
|
||||
if (bundle != null) {
|
||||
String bundleJson = new com.fasterxml.jackson.databind.ObjectMapper()
|
||||
.writeValueAsString(bundle);
|
||||
storageService.store("bundles/" + siteId + ".json", bundleJson);
|
||||
bundleCount++;
|
||||
}
|
||||
// 直接读取已发布的快照(此时 publishChanged 已执行完毕,缓存中有最新数据)
|
||||
String activeJson = snapshotService.getActiveBundleJson(siteId);
|
||||
if (activeJson != null && !activeJson.isEmpty()) {
|
||||
storageService.store("bundles/" + siteId + ".json", activeJson);
|
||||
bundleCount++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("生成兼容 bundle 失败 siteId={}: {}", siteId, e.getMessage());
|
||||
|
||||
@@ -156,6 +156,12 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
|
||||
snapshot.setStatus("draft");
|
||||
|
||||
snapshotMapper.insert(snapshot);
|
||||
|
||||
// 刷新 draft 和 preview 缓存(审批通过后异步生成 draft,需立即可被预览查询到)
|
||||
String bundleJson = toBundleJson(snapshot);
|
||||
draftJsonCache.put(siteId, bundleJson);
|
||||
previewJsonCache.put(siteId, bundleJson);
|
||||
|
||||
log.info("快照已更新: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8));
|
||||
return snapshot;
|
||||
} catch (Exception e) {
|
||||
@@ -195,9 +201,10 @@ public class SiteSnapshotServiceImpl implements SiteSnapshotService {
|
||||
|
||||
snapshotMapper.insert(snapshot);
|
||||
|
||||
// 刷新 draft 缓存
|
||||
// 刷新 draft 和 preview 缓存
|
||||
String bundleJson = toBundleJson(snapshot);
|
||||
draftJsonCache.put(siteId, bundleJson);
|
||||
previewJsonCache.put(siteId, bundleJson);
|
||||
|
||||
log.info("草稿已保存: siteId={}, version={}, checksum={}", siteId, newVersion, checksum.substring(0, 8));
|
||||
return snapshot;
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
<h2 style="margin:0">站点编辑: {{ editSiteId }}</h2>
|
||||
<div style="display:flex;gap:8px">
|
||||
<el-button size="small" @click="editSiteId=''">返回列表</el-button>
|
||||
<el-button size="small" @click="saveSite" :loading="saving">保存站点</el-button>
|
||||
<el-button size="small" @click="saveDraft" :loading="savingDraft">保存草稿</el-button>
|
||||
<el-button size="small" type="success" @click="publishSite" :loading="publishing">发布正式版</el-button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user