فهرست منبع

:art: 细化云端同步锁提升稳定性 https://github.com/siyuan-note/siyuan/issues/5887

Liang Ding 2 سال پیش
والد
کامیت
e295c354d1
3فایلهای تغییر یافته به همراه7 افزوده شده و 4 حذف شده
  1. 2 0
      kernel/model/assets.go
  2. 3 2
      kernel/model/format.go
  3. 2 2
      kernel/model/import.go

+ 2 - 0
kernel/model/assets.go

@@ -141,6 +141,8 @@ func NetImg2LocalAssets(rootID string) (err error) {
 				name = util.FilterFileName(name)
 				name = "net-img-" + name + "-" + ast.NewNodeID() + ext
 				writePath := filepath.Join(util.DataDir, "assets", name)
+				writingDataLock.Lock()
+				defer writingDataLock.Unlock()
 				if err = gulu.File.WriteFileSafer(writePath, data, 0644); nil != err {
 					logging.LogErrorf("write downloaded net img [%s] to local assets [%s] failed: %s", u, writePath, err)
 					return ast.WalkSkipChildren

+ 3 - 2
kernel/model/format.go

@@ -26,7 +26,6 @@ import (
 	"github.com/88250/lute/render"
 	"github.com/siyuan-note/filelock"
 	"github.com/siyuan-note/logging"
-	"github.com/siyuan-note/siyuan/kernel/sql"
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 
@@ -39,6 +38,8 @@ func AutoSpace(rootID string) (err error) {
 	util.PushEndlessProgress(Conf.Language(116))
 	defer util.ClearPushProgress(100)
 
+	WaitForWritingFiles()
+
 	generateFormatHistory(tree)
 	luteEngine := NewLute()
 	// 合并相邻的同类行级节点
@@ -76,7 +77,7 @@ func AutoSpace(rootID string) (err error) {
 	if nil != err {
 		return
 	}
-	sql.WaitForWritingDatabase()
+	util.RandomSleep(500, 700)
 	return
 }
 

+ 2 - 2
kernel/model/import.go

@@ -351,8 +351,6 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
 	util.PushEndlessProgress(Conf.Language(73))
 
 	WaitForWritingFiles()
-	writingDataLock.Lock()
-	defer writingDataLock.Unlock()
 
 	var baseHPath, baseTargetPath, boxLocalPath string
 	if "/" == toPath {
@@ -503,6 +501,8 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
 			})
 
 			reassignIDUpdated(tree)
+			writingDataLock.Lock()
+			defer writingDataLock.Unlock()
 			if err = filesys.WriteTree(tree); nil != err {
 				return io.EOF
 			}