mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 16:40:13 +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()
|
filesys.ReleaseAllFileLocks()
|
||||||
|
|
||||||
passwd := Conf.E2EEPasswd
|
passwd := Conf.E2EEPasswd
|
||||||
unchanged, removed, err := unchangedDataList(passwd)
|
unchangedDataList, removedSyncList, err := calcUnchangedDataList(passwd)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
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 {
|
if nil != err {
|
||||||
util.LogErrorf("encrypt data dir failed: %s", err)
|
util.LogErrorf("encrypt data dir failed: %s", err)
|
||||||
return
|
return
|
||||||
|
|
@ -993,8 +993,8 @@ func unchangedSyncList() (ret map[string]bool, removes []string, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// unchangedDataList 获取 sync 和 data 一致(没有修改过)的文件列表,并删除 sync 中不存在于 data 中的多余文件。
|
// calcUnchangedDataList 计算 sync 和 data 一致(没有修改过)的文件列表 unchangedDataList,并删除 sync 中不存在于 data 中的多余文件 removedSyncList。
|
||||||
func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList map[string]bool, err error) {
|
func calcUnchangedDataList(passwd string) (unchangedDataList map[string]bool, removedSyncList map[string]bool, err error) {
|
||||||
syncDir := Conf.Sync.GetSaveDir()
|
syncDir := Conf.Sync.GetSaveDir()
|
||||||
meta := filepath.Join(syncDir, pathJSON)
|
meta := filepath.Join(syncDir, pathJSON)
|
||||||
if !gulu.File.IsExist(meta) {
|
if !gulu.File.IsExist(meta) {
|
||||||
|
|
@ -1015,8 +1015,8 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
unchangedList = map[string]bool{}
|
unchangedDataList = map[string]bool{}
|
||||||
removeList = map[string]bool{}
|
removedSyncList = map[string]bool{}
|
||||||
filepath.Walk(syncDir, func(path string, info fs.FileInfo, _ error) error {
|
filepath.Walk(syncDir, func(path string, info fs.FileInfo, _ error) error {
|
||||||
if syncDir == path || pathJSON == info.Name() {
|
if syncDir == path || pathJSON == info.Name() {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -1026,7 +1026,7 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
||||||
encryptedP = filepath.ToSlash(encryptedP)
|
encryptedP = filepath.ToSlash(encryptedP)
|
||||||
decryptedP := metaJSON[encryptedP]
|
decryptedP := metaJSON[encryptedP]
|
||||||
if "" == decryptedP { // 理论上不会发生
|
if "" == decryptedP { // 理论上不会发生
|
||||||
removeList[path] = true
|
removedSyncList[path] = true
|
||||||
if gulu.File.IsDir(path) {
|
if gulu.File.IsDir(path) {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
|
|
@ -1035,7 +1035,7 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
||||||
dataP := filepath.Join(util.DataDir, decryptedP)
|
dataP := filepath.Join(util.DataDir, decryptedP)
|
||||||
dataP = filepath.FromSlash(dataP)
|
dataP = filepath.FromSlash(dataP)
|
||||||
if !gulu.File.IsExist(dataP) { // data 已经删除的文件
|
if !gulu.File.IsExist(dataP) { // data 已经删除的文件
|
||||||
removeList[path] = true
|
removedSyncList[path] = true
|
||||||
if gulu.File.IsDir(path) {
|
if gulu.File.IsDir(path) {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
|
|
@ -1045,14 +1045,14 @@ func unchangedDataList(passwd string) (unchangedList map[string]bool, removeList
|
||||||
stat, _ := os.Stat(dataP)
|
stat, _ := os.Stat(dataP)
|
||||||
dataModTime := stat.ModTime()
|
dataModTime := stat.ModTime()
|
||||||
if info.ModTime() == dataModTime {
|
if info.ModTime() == dataModTime {
|
||||||
unchangedList[dataP] = true
|
unchangedDataList[dataP] = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// 在 sync 中删除 data 中已经删除的文件
|
// 在 sync 中删除 data 中已经删除的文件
|
||||||
for remove, _ := range removeList {
|
for remove, _ := range removedSyncList {
|
||||||
if strings.HasSuffix(remove, "index.json") {
|
if strings.HasSuffix(remove, "index.json") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue