Ver código fonte

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 1 ano atrás
pai
commit
79528e094d

+ 3 - 1
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

+ 2 - 1
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)
@@ -1919,7 +1921,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)

+ 2 - 0
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
 }
 

+ 10 - 2
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

+ 1 - 1
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)
 }