mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 08:30:12 +01:00
🎨 优化云端同步资源占用 https://github.com/siyuan-note/siyuan/issues/5093
This commit is contained in:
parent
1acfe53098
commit
bceb37b108
1 changed files with 11 additions and 11 deletions
|
|
@ -595,13 +595,13 @@ func workspaceData2SyncDir() (err error) {
|
|||
filesys.ReleaseAllFileLocks()
|
||||
|
||||
passwd := Conf.E2EEPasswd
|
||||
unchanged, removed, err := unchangedDataList(passwd)
|
||||
unchangedDataList, removedSyncList, err := calcUnchangedDataList(passwd)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
_ = removed // TODO: 支持多设备操作不同文档后云端同步合并 https://github.com/siyuan-note/siyuan/issues/5092
|
||||
_ = removedSyncList // TODO: 支持多设备操作不同文档后云端同步合并 https://github.com/siyuan-note/siyuan/issues/5092
|
||||
|
||||
encryptedDataDir, err := prepareSyncData(passwd, unchanged)
|
||||
encryptedDataDir, err := prepareSyncData(passwd, unchangedDataList)
|
||||
if nil != err {
|
||||
util.LogErrorf("encrypt data dir failed: %s", err)
|
||||
return
|
||||
|
|
@ -993,8 +993,8 @@ func unchangedSyncList() (ret map[string]bool, removes []string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// unchangedDataList 获取 sync 和 data 一致(没有修改过)的文件列表,并删除 sync 中不存在于 data 中的多余文件。
|
||||
func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList map[string]bool, err error) {
|
||||
// calcUnchangedDataList 计算 sync 和 data 一致(没有修改过)的文件列表 unchangedDataList,并删除 sync 中不存在于 data 中的多余文件 removedSyncList。
|
||||
func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, removedSyncList map[string]bool, err error) {
|
||||
syncDir := Conf.Sync.GetSaveDir()
|
||||
meta := filepath.Join(syncDir, pathJSON)
|
||||
if !gulu.File.IsExist(meta) {
|
||||
|
|
@ -1015,8 +1015,8 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
|||
return
|
||||
}
|
||||
|
||||
unchangedList = map[string]bool{}
|
||||
removeList = map[string]bool{}
|
||||
unchangedDataList = map[string]bool{}
|
||||
removedSyncList = map[string]bool{}
|
||||
filepath.Walk(syncDir, func(path string, info fs.FileInfo, _ error) error {
|
||||
if syncDir == path || pathJSON == info.Name() {
|
||||
return nil
|
||||
|
|
@ -1026,7 +1026,7 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
|||
encryptedP = filepath.ToSlash(encryptedP)
|
||||
decryptedP := metaJSON[encryptedP]
|
||||
if "" == decryptedP { // 理论上不会发生
|
||||
removeList[path] = true
|
||||
removedSyncList[path] = true
|
||||
if gulu.File.IsDir(path) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
|
@ -1035,7 +1035,7 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
|||
dataP := filepath.Join(util.DataDir, decryptedP)
|
||||
dataP = filepath.FromSlash(dataP)
|
||||
if !gulu.File.IsExist(dataP) { // data 已经删除的文件
|
||||
removeList[path] = true
|
||||
removedSyncList[path] = true
|
||||
if gulu.File.IsDir(path) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
|
@ -1045,14 +1045,14 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
|||
stat, _ := os.Stat(dataP)
|
||||
dataModTime := stat.ModTime()
|
||||
if info.ModTime() == dataModTime {
|
||||
unchangedList[dataP] = true
|
||||
unchangedDataList[dataP] = true
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// 在 sync 中删除 data 中已经删除的文件
|
||||
for remove, _ := range removeList {
|
||||
for remove, _ := range removedSyncList {
|
||||
if strings.HasSuffix(remove, "index.json") {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue