From 339020a282877aa49d71b5d4b6564fea9a47e8f1 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 19 Dec 2023 16:40:36 +0800 Subject: [PATCH 1/4] :art: Improve kernel stability https://github.com/siyuan-note/siyuan/issues/9912 --- kernel/api/filetree.go | 4 +++- kernel/model/file.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index bac16c6cc..fb92337f5 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -432,6 +432,7 @@ func createDoc(c *gin.Context) { return } + model.WaitForWritingFiles() box := model.Conf.Box(notebook) pushCreate(box, p, tree.Root.ID, arg) @@ -461,8 +462,8 @@ func createDailyNote(c *gin.Context) { return } - box := model.Conf.Box(notebook) model.WaitForWritingFiles() + box := model.Conf.Box(notebook) luteEngine := util.NewLute() tree, err := filesys.LoadTree(box.ID, p, luteEngine) if nil != err { @@ -549,6 +550,7 @@ func createDocWithMd(c *gin.Context) { } ret.Data = id + model.WaitForWritingFiles() box := model.Conf.Box(notebook) b, _ := model.GetBlock(id, nil) p := b.Path diff --git a/kernel/model/file.go b/kernel/model/file.go index c9b4153ce..7b63db4a6 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1015,6 +1015,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree return } + WaitForWritingFiles() ChangeFileTreeSort(box.ID, sorts) return } @@ -1033,6 +1034,7 @@ func CreateWithMarkdown(boxID, hPath, md, parentID, id string) (retID string, er luteEngine := util.NewLute() dom := luteEngine.Md2BlockDOM(md, false) retID, err = createDocsByHPath(box.ID, hPath, dom, parentID, id) + WaitForWritingFiles() return } From 3907165090cdeac9d735edc9ccd76f6c8c0f4a8b Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 19 Dec 2023 17:07:04 +0800 Subject: [PATCH 2/4] :art: Improve database table view --- kernel/model/attribute_view.go | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index ae5241ad9..93cc157fb 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1919,7 +1919,6 @@ func getNodeByBlockID(tx *Transaction, blockID string) (node *ast.Node, tree *pa tree, err = loadTreeByBlockID(blockID) } if nil != err { - logging.LogWarnf("load tree by block id [%s] failed: %s", blockID, err) return } node = treenode.GetNodeInTree(tree, blockID) From d8fb5f896e2ebf7ad8161021a3e2c855fa628b4d Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 19 Dec 2023 20:03:13 +0800 Subject: [PATCH 3/4] :art: Improve kernel stability https://github.com/siyuan-note/siyuan/issues/9912 --- kernel/model/mount.go | 12 ++++++++++-- kernel/model/transaction.go | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/kernel/model/mount.go b/kernel/model/mount.go index 37616a099..04fabe4df 100644 --- a/kernel/model/mount.go +++ b/kernel/model/mount.go @@ -41,6 +41,11 @@ func CreateBox(name string) (id string, err error) { return } + WaitForWritingFiles() + + createDocLock.Lock() + defer createDocLock.Unlock() + id = ast.NewNodeID() boxLocalPath := filepath.Join(util.DataDir, id) err = os.MkdirAll(boxLocalPath, 0755) @@ -71,12 +76,15 @@ func RenameBox(boxID, name string) (err error) { } func RemoveBox(boxID string) (err error) { - WaitForWritingFiles() - if util.IsReservedFilename(boxID) { return errors.New(fmt.Sprintf("can not remove [%s] caused by it is a reserved file", boxID)) } + WaitForWritingFiles() + + createDocLock.Lock() + defer createDocLock.Unlock() + localPath := filepath.Join(util.DataDir, boxID) if !filelock.IsExist(localPath) { return diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 6bc09252d..73608c33d 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -87,7 +87,7 @@ var ( ) func isWritingFiles() bool { - time.Sleep(time.Duration(20) * time.Millisecond) + time.Sleep(time.Duration(50) * time.Millisecond) return 0 < len(txQueue) } From 5bc3152635b9819a4e6ddaccd3e03df36b13f42a Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Tue, 19 Dec 2023 21:02:23 +0800 Subject: [PATCH 4/4] :art: Improve kernel stability https://github.com/siyuan-note/siyuan/issues/9912 --- kernel/model/attribute_view.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 93cc157fb..5cced0a87 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -1694,6 +1694,8 @@ func replaceAttributeViewBlock(operation *Operation, tx *Transaction) (err error return } + WaitForWritingFiles() + var node *ast.Node if !operation.IsDetached { node, _, _ = getNodeByBlockID(tx, operation.NextID)