An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve av https://github.com/siyuan-note/siyuan/issues/14511
Daniel7bd690ececbe
diff --git a/kernel/av/av.go b/kernel/av/av.goindex 6a291ffb6a..a886ca49ba 100644--- a/kernel/av/av.go+++ b/kernel/av/av.go@@ -582,6 +582,19 @@ func (av *AttributeView) ExistBoundBlock(nodeID string) bool {return false}+func (av *AttributeView) GetBlockValueByBoundID(nodeID string) *Value {+ for _, kv := range av.KeyValues {+ if KeyTypeBlock == kv.Key.Type {+ for _, v := range kv.Values {+ if v.Block.ID == nodeID {+ return v+ }+ }+ }+ }+ return nil+}+func (av *AttributeView) GetValue(keyID, itemID string) (ret *Value) {for _, kv := range av.KeyValues {if kv.Key.ID == keyID {diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex e06a0d2235..fbb10dec0b 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -1267,11 +1267,11 @@ type BlockAttributeViewKeys struct {KeyValues []*av.KeyValues `json:"keyValues"`}-func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {+func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {waitForSyncingStorages()ret = []*BlockAttributeViewKeys{}- attrs := sql.GetBlockAttrs(blockID)+ attrs := sql.GetBlockAttrs(nodeID)avs := attrs[av.NodeAttrNameAvs]if "" == avs {return@@ -1289,13 +1289,19 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {attrViewCache[avID] = attrView}- if !attrView.ExistBoundBlock(blockID) {+ if !attrView.ExistBoundBlock(nodeID) {// 比如剪切后粘贴,块 ID 会变,但是属性还在块上,这里做一次数据订正// Auto verify the database name when clicking the block superscript icon https://github.com/siyuan-note/siyuan/issues/10861- unbindBlockAv(nil, avID, blockID)+ unbindBlockAv(nil, avID, nodeID)return}+ blockVal := attrView.GetBlockValueByBoundID(nodeID)+ if nil == blockVal {+ continue+ }++ itemID := blockVal.BlockIDvar keyValues []*av.KeyValuesfor _, kv := range attrView.KeyValues {if av.KeyTypeLineNumber == kv.Key.Type {@@ -1306,20 +1312,20 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {kValues := &av.KeyValues{Key: kv.Key}for _, v := range kv.Values {- if v.BlockID == blockID {+ if v.BlockID == itemID {kValues.Values = append(kValues.Values, v)}}switch kValues.Key.Type {case av.KeyTypeRollup:- kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeRollup, Rollup: &av.ValueRollup{Contents: []*av.Value{}}})+ kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeRollup, Rollup: &av.ValueRollup{Contents: []*av.Value{}}})case av.KeyTypeTemplate:- kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{Content: ""}})+ kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeTemplate, Template: &av.ValueTemplate{Content: ""}})case av.KeyTypeCreated:- kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeCreated})+ kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeCreated})case av.KeyTypeUpdated:- kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: blockID, Type: av.KeyTypeUpdated})+ kValues.Values = append(kValues.Values, &av.Value{ID: ast.NewNodeID(), KeyID: kValues.Key.ID, BlockID: itemID, Type: av.KeyTypeUpdated})case av.KeyTypeNumber:for _, v := range kValues.Values {if nil != v.Number {@@ -1336,7 +1342,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {keyValues = append(keyValues, kValues)} else {// 如果没有值,那么就补一个默认值- kValues.Values = append(kValues.Values, av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, blockID, kv.Key.Type))+ kValues.Values = append(kValues.Values, av.GetAttributeViewDefaultValue(ast.NewNodeID(), kv.Key.ID, itemID, kv.Key.Type))keyValues = append(keyValues, kValues)}}@@ -1347,7 +1353,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {switch kv.Key.Type {case av.KeyTypeBlock: // 对于主键可能需要填充静态锚文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049if nil != kv.Values[0].Block {- ial := sql.GetBlockAttrs(blockID)+ ial := sql.GetBlockAttrs(nodeID)if v := ial[av.NodeAttrViewStaticText+"-"+attrView.ID]; "" != v {kv.Values[0].Block.Content = v}@@ -1419,7 +1425,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {kv.Values[0].Relation.Contents = append(kv.Values[0].Relation.Contents, blocks[bID])}case av.KeyTypeCreated:- createdStr := blockID[:len("20060102150405")]+ createdStr := nodeID[:len("20060102150405")]created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)if nil == parseErr {kv.Values[0].Created = av.NewFormattedValueCreated(created.UnixMilli(), 0, av.CreatedFormatNone)@@ -1429,7 +1435,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {kv.Values[0].Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)}case av.KeyTypeUpdated:- ial := sql.GetBlockAttrs(blockID)+ ial := sql.GetBlockAttrs(nodeID)updatedStr := ial["updated"]updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)if nil == parseErr {@@ -1457,7 +1463,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {}if nil == kv.Values[0].Template {- kv.Values[0] = av.GetAttributeViewDefaultValue(kv.Values[0].ID, kv.Key.ID, blockID, kv.Key.Type)+ kv.Values[0] = av.GetAttributeViewDefaultValue(kv.Values[0].ID, kv.Key.ID, nodeID, kv.Key.Type)}var renderErr error@@ -1503,9 +1509,9 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {}}if 1 > len(blockIDs) {- tree, _ := LoadTreeByBlockID(blockID)+ tree, _ := LoadTreeByBlockID(nodeID)if nil != tree {- node := treenode.GetNodeInTree(tree, blockID)+ node := treenode.GetNodeInTree(tree, nodeID)if nil != node {if removeErr := removeNodeAvID(node, avID, nil, tree); nil != removeErr {logging.LogErrorf("remove node avID [%s] failed: %s", avID, removeErr)