MCPcopy
hub / github.com/chavyleung/scripts / upgradeGlobalBaks

Function upgradeGlobalBaks

chavy.box.js:1081–1111  ·  view source on GitHub ↗

* 升级备份数据 * * 升级前: 把所有备份都存到一个持久化空间 * 升级后: 把每个备份都独立存到一个空间, `$.KEY_backups` 仅记录必要的数据索引

()

Source from the content-addressed store, hash-verified

1079 * 升级后: 把每个备份都独立存到一个空间, `$.KEY_backups` 仅记录必要的数据索引
1080 */
1081function upgradeGlobalBaks() {
1082 let oldbaks = $.getdata($.KEY_globalBaks)
1083 let newbaks = $.getjson($.KEY_backups, [])
1084 const isEmpty = (bak) => [undefined, null, ''].includes(bak)
1085 const isExistsInNew = (backupId) => newbaks.find((bak) => bak.id === backupId)
1086
1087 // 存在旧备份数据时, 升级备份数据格式
1088 if (!isEmpty(oldbaks)) {
1089 oldbaks = JSON.parse(oldbaks)
1090 oldbaks.forEach((bak) => {
1091 if (isEmpty(bak)) return
1092 if (isEmpty(bak.bak)) return
1093 if (isExistsInNew(bak.id)) return
1094
1095 console.log(`正在迁移: ${bak.name}`)
1096 const backupId = bak.id
1097 const backupData = bak.bak
1098
1099 // 删除旧的备份数据, 仅保留索引信息
1100 delete bak.bak
1101 newbaks.push(bak)
1102
1103 // 提取旧备份数据, 存入独立的持久化空间
1104 $.setjson(backupData, backupId)
1105 })
1106 $.setjson(newbaks, $.KEY_backups)
1107 }
1108
1109 // 清空所有旧备份的数据
1110 $.setdata('', $.KEY_globalBaks)
1111}
1112
1113function updateCurSesssions(appId, data) {
1114 if (!appId) {

Callers 1

chavy.box.jsFile · 0.70

Calls 7

isEmptyFunction · 0.70
isExistsInNewFunction · 0.70
getdataMethod · 0.45
getjsonMethod · 0.45
logMethod · 0.45
setjsonMethod · 0.45
setdataMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…