Improve data sync performance for booting https://github.com/siyuan-note/siyuan/issues/13216

This commit is contained in:
Daniel 2024-11-21 10:59:29 +08:00
parent eba4dfa0da
commit 89f1887c3b
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
16 changed files with 153 additions and 113 deletions

View file

@ -311,9 +311,9 @@ func GetAssetAbsPath(relativePath string) (ret string, err error) {
// 在笔记本下搜索
for _, notebook := range notebooks {
notebookAbsPath := filepath.Join(util.DataDir, notebook.ID)
filelock.Walk(notebookAbsPath, func(path string, info fs.FileInfo, _ error) error {
if isSkipFile(info.Name()) {
if info.IsDir() {
filelock.Walk(notebookAbsPath, func(path string, d fs.DirEntry, err error) error {
if isSkipFile(d.Name()) {
if d.IsDir() {
return filepath.SkipDir
}
return nil
@ -1270,12 +1270,12 @@ func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
// 笔记本 assets
for _, notebook := range notebooks {
notebookAbsPath := filepath.Join(util.DataDir, notebook.ID)
filelock.Walk(notebookAbsPath, func(path string, info fs.FileInfo, err error) error {
filelock.Walk(notebookAbsPath, func(path string, d fs.DirEntry, err error) error {
if notebookAbsPath == path {
return nil
}
if isSkipFile(info.Name()) {
if info.IsDir() {
if isSkipFile(d.Name()) {
if d.IsDir() {
return filepath.SkipDir
}
return nil
@ -1286,20 +1286,20 @@ func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
return nil
}
if info.IsDir() && "assets" == info.Name() {
filelock.Walk(path, func(assetPath string, info fs.FileInfo, err error) error {
if d.IsDir() && "assets" == d.Name() {
filelock.Walk(path, func(assetPath string, d fs.DirEntry, err error) error {
if path == assetPath {
return nil
}
if isSkipFile(info.Name()) {
if info.IsDir() {
if isSkipFile(d.Name()) {
if d.IsDir() {
return filepath.SkipDir
}
return nil
}
relPath := filepath.ToSlash(assetPath)
relPath = relPath[strings.Index(relPath, "assets/"):]
if info.IsDir() {
if d.IsDir() {
relPath += "/"
}
assetsAbsPathMap[relPath] = assetPath
@ -1313,13 +1313,13 @@ func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
// 全局 assets
dataAssetsAbsPath := util.GetDataAssetsAbsPath()
filelock.Walk(dataAssetsAbsPath, func(assetPath string, info fs.FileInfo, err error) error {
filelock.Walk(dataAssetsAbsPath, func(assetPath string, d fs.DirEntry, err error) error {
if dataAssetsAbsPath == assetPath {
return nil
}
if isSkipFile(info.Name()) {
if info.IsDir() {
if isSkipFile(d.Name()) {
if d.IsDir() {
return filepath.SkipDir
}
return nil
@ -1332,7 +1332,7 @@ func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
relPath := filepath.ToSlash(assetPath)
relPath = relPath[strings.Index(relPath, "assets/"):]
if info.IsDir() {
if d.IsDir() {
relPath += "/"
}
assetsAbsPathMap[relPath] = assetPath
@ -1356,14 +1356,12 @@ func copyDocAssetsToDataAssets(boxID, parentDocPath string) {
func copyAssetsToDataAssets(rootPath string) {
var assetsDirPaths []string
filelock.Walk(rootPath, func(path string, info fs.FileInfo, err error) error {
if rootPath == path || nil == info {
filelock.Walk(rootPath, func(path string, d fs.DirEntry, err error) error {
if nil != err || rootPath == path || nil == d {
return nil
}
isDir := info.IsDir()
name := info.Name()
isDir, name := d.IsDir(), d.Name()
if isSkipFile(name) {
if isDir {
return filepath.SkipDir