Explorar o código

:art: 优化云端同步上传资源占用和耗时 https://github.com/siyuan-note/siyuan/issues/5093

Liang Ding %!s(int64=3) %!d(string=hai) anos
pai
achega
e8351aab04
Modificáronse 2 ficheiros con 29 adicións e 6 borrados
  1. 19 3
      kernel/model/osssync.go
  2. 10 3
      kernel/model/sync.go

+ 19 - 3
kernel/model/osssync.go

@@ -20,6 +20,7 @@ import (
 	"context"
 	"errors"
 	"fmt"
+	"io"
 	"io/fs"
 	"os"
 	"path"
@@ -801,10 +802,21 @@ func localUpsertRemoveListOSS(localDirPath string, cloudFileList map[string]*Clo
 			return nil
 		}
 
-		localModTime := info.ModTime().Unix()
-		if cloudIdx.Updated == localModTime {
+		// TODO: 优化云端同步上传资源占用和耗时 https://github.com/siyuan-note/siyuan/issues/5093
+		localHash, hashErr := util.GetEtag(path)
+		if nil != hashErr {
+			err = hashErr
+			return io.EOF
+		}
+
+		if cloudIdx.Hash == localHash {
 			unchanged[relPath] = true
 		}
+
+		//localModTime := info.ModTime().Unix()
+		//if cloudIdx.Updated == localModTime {
+		//	unchanged[relPath] = true
+		//}
 		return nil
 	})
 
@@ -859,10 +871,14 @@ func cloudUpsertRemoveListOSS(localDirPath string, cloudFileList, localFileList
 			cloudRemoves = append(cloudRemoves, cloudFile)
 			continue
 		}
-		if localIdx.Updated == cloudIdx.Updated {
+		if localIdx.Hash == cloudIdx.Hash {
 			unchanged[filepath.Join(localDirPath, cloudFile)] = true
 			continue
 		}
+		//if localIdx.Updated == cloudIdx.Updated {
+		//	unchanged[filepath.Join(localDirPath, cloudFile)] = true
+		//	continue
+		//}
 
 		cloudChangedList[cloudFile] = true
 	}

+ 10 - 3
kernel/model/sync.go

@@ -607,8 +607,9 @@ func workspaceData2SyncDir() (removeList, upsertList map[string]bool, err error)
 }
 
 type CloudIndex struct {
-	Size    int64 `json:"size"`
-	Updated int64 `json:"updated"` // Unix timestamp 秒
+	Hash    string `json:"hash"`
+	Size    int64  `json:"size"`
+	Updated int64  `json:"updated"` // Unix timestamp 秒
 }
 
 // genCloudIndex 生成云端索引文件。
@@ -628,7 +629,13 @@ func genCloudIndex(localDirPath string, excludes map[string]bool) (cloudIndex ma
 
 		p := strings.TrimPrefix(path, localDirPath)
 		p = filepath.ToSlash(p)
-		cloudIndex[p] = &CloudIndex{Size: info.Size(), Updated: info.ModTime().Unix()}
+		// TODO: 优化云端同步上传资源占用和耗时 https://github.com/siyuan-note/siyuan/issues/5093
+		hash, hashErr := util.GetEtag(path)
+		if nil != hashErr {
+			err = hashErr
+			return io.EOF
+		}
+		cloudIndex[p] = &CloudIndex{Hash: hash, Size: info.Size(), Updated: info.ModTime().Unix()}
 		return nil
 	})
 	if nil != err {