From c1bc0c2b0e363b60e24b3e9e18d0fa3cff2e9718 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 27 Sep 2023 15:51:27 +0800 Subject: [PATCH 1/5] :art: Database values no longer correspond to block attributes Fix https://github.com/siyuan-note/siyuan/issues/9293 --- kernel/filesys/json_parser.go | 8 ++++++++ kernel/model/attribute_view.go | 12 +----------- kernel/model/import.go | 8 +++----- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/kernel/filesys/json_parser.go b/kernel/filesys/json_parser.go index da8b3a5d1..192ba7104 100644 --- a/kernel/filesys/json_parser.go +++ b/kernel/filesys/json_parser.go @@ -171,6 +171,14 @@ func fixLegacyData(tip, node *ast.Node, idMap *map[string]bool, needFix, needMig node.Children = node.Children[:len(node.Children)-1] *needFix = true } + + for _, kv := range node.KramdownIAL { + if strings.Contains(kv[0], "custom-av-key-") { + // 删除数据库属性键值对 https://github.com/siyuan-note/siyuan/issues/9293 + node.RemoveIALAttr(kv[0]) + *needFix = true + } + } } if "" != node.ID { if _, ok := (*idMap)[node.ID]; ok { diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index e936027b8..2405de09b 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -519,8 +519,6 @@ func (tx *Transaction) removeAttributeViewBlock(operation *Operation) (err error delete(attrs, "custom-hidden") node.RemoveIALAttr("custom-hidden") } - delete(attrs, NodeAttrNamePrefixAvKey+operation.AvID+"-"+values.KeyID) - node.RemoveIALAttr(NodeAttrNamePrefixAvKey + operation.AvID + "-" + values.KeyID) if avs := attrs[NodeAttrNameAvs]; "" != avs { avIDs := strings.Split(avs, ",") @@ -937,13 +935,6 @@ func UpdateAttributeViewCell(avID, keyID, rowID, cellID string, valueData interf return } - attrs := parse.IAL2Map(node.KramdownIAL) - attrs[NodeAttrNamePrefixAvKey+avID+"-"+val.KeyID] = val.ToJSONString() - - if err = setNodeAttrs(node, tree, attrs); nil != err { - return - } - if err = av.SaveAttributeView(attrView); nil != err { return } @@ -1095,6 +1086,5 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) { } const ( - NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id - NodeAttrNamePrefixAvKey = "custom-av-key-" // 用于标记列 + NodeAttrNameAvs = "custom-avs" // 用于标记块所属的属性视图,逗号分隔 av id ) diff --git a/kernel/model/import.go b/kernel/model/import.go index 383beedbd..e8c5c0ae0 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -153,10 +153,8 @@ func ImportSY(zipPath, boxID, toPath string) (err error) { // 重新指向数据库属性值 ial := parse.IAL2Map(n.KramdownIAL) - for k, v := range ial { - if strings.HasPrefix(k, NodeAttrNamePrefixAvKey) { - v = strings.ReplaceAll(v, oldNodeID, newNodeID) - n.SetIALAttr(k, v) + for k, _ := range ial { + if strings.HasPrefix(k, NodeAttrNameAvs) { avBlockIDs[oldNodeID] = newNodeID } } @@ -259,7 +257,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) { ial := parse.IAL2Map(n.KramdownIAL) for k, v := range ial { - if strings.HasPrefix(k, NodeAttrNamePrefixAvKey) || strings.HasPrefix(k, NodeAttrNameAvs) { + if strings.HasPrefix(k, NodeAttrNameAvs) { newKey, newVal := k, v for oldAvID, newAvID := range avIDs { newKey = strings.ReplaceAll(newKey, oldAvID, newAvID) From 4c47fdbdb195a3fab5928d93e61d062a3b9e3ad3 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 27 Sep 2023 15:58:30 +0800 Subject: [PATCH 2/5] :art: Remove `scroll` attribute when converting the document to a heading https://github.com/siyuan-note/siyuan/issues/9297 --- kernel/model/heading.go | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/model/heading.go b/kernel/model/heading.go index 47ae237e0..dc41413bd 100644 --- a/kernel/model/heading.go +++ b/kernel/model/heading.go @@ -160,6 +160,7 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st headingLevel = 6 } + srcTree.Root.RemoveIALAttr("scroll") // Remove `scroll` attribute when converting the document to a heading https://github.com/siyuan-note/siyuan/issues/9297 srcTree.Root.RemoveIALAttr("type") tagIAL := srcTree.Root.IALAttr("tags") tags := strings.Split(tagIAL, ",") From 3842a17d0760f75410756870c5fbf13572eb5cd1 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 27 Sep 2023 16:11:18 +0800 Subject: [PATCH 3/5] :art: Documents created via the database are no longer automatically hidden Fix https://github.com/siyuan-note/siyuan/issues/9298 --- app/src/protyle/hint/index.ts | 1 - kernel/api/filetree.go | 12 +----------- kernel/model/file.go | 14 +++++--------- kernel/model/path.go | 8 ++++---- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index 28718d05a..c07611692 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -422,7 +422,6 @@ ${genHintItemHTML(item)} const realFileName = fileNames.length === 1 ? fileNames[0] : fileNames[1]; getSavePath(protyle.path, protyle.notebookId, (pathString) => { fetchPost("/api/filetree/createDocWithMd", { - hidden: false, notebook: protyle.notebookId, path: pathPosix().join(pathString, realFileName), parentID: protyle.block.rootID, diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go index f451d026f..c965a05dc 100644 --- a/kernel/api/filetree.go +++ b/kernel/api/filetree.go @@ -481,12 +481,6 @@ func createDocWithMd(c *gin.Context) { parentID = parentIDArg.(string) } - hidden := true - hiddenArg := arg["hidden"] - if nil != hiddenArg { - hidden = hiddenArg.(bool) - } - hPath := arg["path"].(string) markdown := arg["markdown"].(string) @@ -502,7 +496,7 @@ func createDocWithMd(c *gin.Context) { hPath = "/" + hPath } - id, err := model.CreateWithMarkdown(notebook, hPath, markdown, parentID, hidden) + id, err := model.CreateWithMarkdown(notebook, hPath, markdown, parentID) if nil != err { ret.Code = -1 ret.Msg = err.Error() @@ -510,10 +504,6 @@ func createDocWithMd(c *gin.Context) { } ret.Data = id - if !hidden { - return - } - 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 2f12a7f95..cfd8f404c 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1019,7 +1019,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree luteEngine := util.NewLute() dom := luteEngine.Md2BlockDOM(md, false) - tree, err = createDoc(box.ID, p, title, dom, true) + tree, err = createDoc(box.ID, p, title, dom) if nil != err { return } @@ -1028,7 +1028,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree return } -func CreateWithMarkdown(boxID, hPath, md, parentID string, hidden bool) (id string, err error) { +func CreateWithMarkdown(boxID, hPath, md, parentID string) (id string, err error) { box := Conf.Box(boxID) if nil == box { err = errors.New(Conf.Language(0)) @@ -1038,7 +1038,7 @@ func CreateWithMarkdown(boxID, hPath, md, parentID string, hidden bool) (id stri WaitForWritingFiles() luteEngine := util.NewLute() dom := luteEngine.Md2BlockDOM(md, false) - id, _, err = createDocsByHPath(box.ID, hPath, dom, parentID, hidden) + id, _, err = createDocsByHPath(box.ID, hPath, dom, parentID) return } @@ -1442,7 +1442,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) { return } - id, existed, err := createDocsByHPath(box.ID, hPath, "", "", true) + id, existed, err := createDocsByHPath(box.ID, hPath, "", "") if nil != err { return } @@ -1487,7 +1487,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) { return } -func createDoc(boxID, p, title, dom string, hidden bool) (tree *parse.Tree, err error) { +func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) { title = gulu.Str.RemoveInvisible(title) if 512 < utf8.RuneCountInString(title) { // 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299 @@ -1559,10 +1559,6 @@ func createDoc(boxID, p, title, dom string, hidden bool) (tree *parse.Tree, err tree.Root.AppendChild(treenode.NewParagraph()) } - if !hidden { - tree.Root.SetIALAttr("custom-hidden", "true") - } - transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}} PerformTransactions(&[]*Transaction{transaction}) WaitForWritingFiles() diff --git a/kernel/model/path.go b/kernel/model/path.go index 3cfc18420..ee9fe774b 100644 --- a/kernel/model/path.go +++ b/kernel/model/path.go @@ -33,7 +33,7 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) -func createDocsByHPath(boxID, hPath, content, parentID string, hidden bool) (id string, existed bool, err error) { +func createDocsByHPath(boxID, hPath, content, parentID string) (id string, existed bool, err error) { hPath = strings.TrimSuffix(hPath, ".sy") pathBuilder := bytes.Buffer{} pathBuilder.WriteString("/") @@ -51,7 +51,7 @@ func createDocsByHPath(boxID, hPath, content, parentID string, hidden bool) (id // 如果父文档存在且 ID 一致,则直接在父文档下创建 id = ast.NewNodeID() p := strings.TrimSuffix(preferredParent.Path, ".sy") + "/" + id + ".sy" - if _, err = createDoc(boxID, p, name, content, hidden); nil != err { + if _, err = createDoc(boxID, p, name, content); nil != err { return } } @@ -68,11 +68,11 @@ func createDocsByHPath(boxID, hPath, content, parentID string, hidden bool) (id pathBuilder.WriteString(id) docP := pathBuilder.String() + ".sy" if isNotLast { - if _, err = createDoc(boxID, docP, part, "", hidden); nil != err { + if _, err = createDoc(boxID, docP, part, ""); nil != err { return } } else { - if _, err = createDoc(boxID, docP, part, content, hidden); nil != err { + if _, err = createDoc(boxID, docP, part, content); nil != err { return } } From 688f3a13bf3774c42875d668eeaf985bf018f885 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 27 Sep 2023 16:23:46 +0800 Subject: [PATCH 4/5] :art: New a row in the database no longer require to create a relevant doc https://github.com/siyuan-note/siyuan/issues/9294 --- kernel/model/attribute_view.go | 60 +++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 2405de09b..e8d23ab30 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -25,7 +25,6 @@ import ( "github.com/88250/lute/parse" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/av" - "github.com/siyuan-note/siyuan/kernel/sql" "github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/util" ) @@ -391,6 +390,16 @@ func setAttributeViewColumnCalc(operation *Operation) (err error) { } func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) { + if 1 > len(operation.SrcIDs) { + // 不绑定到任何块的情况,比如直接在属性视图中添加一个块 + // New a row in the database no longer require to create a relevant doc https://github.com/siyuan-note/siyuan/issues/9294 + var avErr error + if avErr = addAttributeViewBlock("", operation, nil, tx); nil != avErr { + return &TxErr{code: TxErrWriteAttributeView, id: operation.AvID, msg: avErr.Error()} + } + return + } + for _, id := range operation.SrcIDs { tree, err := tx.loadTree(id) if nil != err { @@ -407,21 +416,18 @@ func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) } func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tree, tx *Transaction) (err error) { - node := treenode.GetNodeInTree(tree, blockID) - if nil == node { - err = ErrBlockNotFound - return - } + var node *ast.Node + if "" != blockID { + node = treenode.GetNodeInTree(tree, blockID) + if nil == node { + err = ErrBlockNotFound + return + } - if ast.NodeAttributeView == node.Type { - // 不能将一个属性视图拖拽到另一个属性视图中 - return - } - - block := sql.BuildBlockFromNode(node, tree) - if nil == block { - err = ErrBlockNotFound - return + if ast.NodeAttributeView == node.Type { + // 不能将一个属性视图拖拽到另一个属性视图中 + return + } } attrView, err := av.ParseAttributeView(operation.AvID) @@ -445,19 +451,21 @@ func addAttributeViewBlock(blockID string, operation *Operation, tree *parse.Tre value := &av.Value{ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, BlockID: blockID, Type: av.KeyTypeBlock, Block: &av.ValueBlock{ID: blockID, Content: getNodeRefText(node)}} blockValues.Values = append(blockValues.Values, value) - attrs := parse.IAL2Map(node.KramdownIAL) + if nil != node { + attrs := parse.IAL2Map(node.KramdownIAL) - if "" == attrs[NodeAttrNameAvs] { - attrs[NodeAttrNameAvs] = operation.AvID - } else { - avIDs := strings.Split(attrs[NodeAttrNameAvs], ",") - avIDs = append(avIDs, operation.AvID) - avIDs = gulu.Str.RemoveDuplicatedElem(avIDs) - attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",") - } + if "" == attrs[NodeAttrNameAvs] { + attrs[NodeAttrNameAvs] = operation.AvID + } else { + avIDs := strings.Split(attrs[NodeAttrNameAvs], ",") + avIDs = append(avIDs, operation.AvID) + avIDs = gulu.Str.RemoveDuplicatedElem(avIDs) + attrs[NodeAttrNameAvs] = strings.Join(avIDs, ",") + } - if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err { - return + if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err { + return + } } switch view.LayoutType { From 4efdae77453964e5c0cb28eef858fca7a6147735 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 27 Sep 2023 16:39:39 +0800 Subject: [PATCH 5/5] :art: Database values no longer correspond to block attributes Fix https://github.com/siyuan-note/siyuan/issues/9293 --- kernel/filesys/json_parser.go | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/filesys/json_parser.go b/kernel/filesys/json_parser.go index 192ba7104..e333a8e29 100644 --- a/kernel/filesys/json_parser.go +++ b/kernel/filesys/json_parser.go @@ -174,6 +174,7 @@ func fixLegacyData(tip, node *ast.Node, idMap *map[string]bool, needFix, needMig for _, kv := range node.KramdownIAL { if strings.Contains(kv[0], "custom-av-key-") { + // TODO: 数据库正式上线以后移除这里的修复 // 删除数据库属性键值对 https://github.com/siyuan-note/siyuan/issues/9293 node.RemoveIALAttr(kv[0]) *needFix = true