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 `Add to Database` https://github.com/siyuan-note/siyuan/issues/10659
Danielc7c7bdb95029
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 2e76d041c1..c74673904c 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -1174,6 +1174,7 @@ type AvSearchResult struct {AvID string `json:"avID"`AvName string `json:"avName"`ViewName string `json:"viewName"`+ ViewID string `json:"viewID"`BlockID string `json:"blockID"`HPath string `json:"hPath"`Children []*AvSearchResult `json:"children,omitempty"`@@ -1264,96 +1265,80 @@ func SearchAttributeView(keyword string, excludeAvIDs []string) (ret []*AvSearchavIDs = append(avIDs, a.AvID)}- avBlocks := treenode.BatchGetMirrorAttrViewBlocks(avIDs)var blockIDs []string- for _, avBlock := range avBlocks {- blockIDs = append(blockIDs, avBlock.BlockIDs...)+ for _, bIDs := range avBlockRels {+ blockIDs = append(blockIDs, bIDs...)}blockIDs = gulu.Str.RemoveDuplicatedElem(blockIDs)trees := filesys.LoadTrees(blockIDs)- for _, avBlock := range avBlocks {- if 1 > len(avBlock.BlockIDs) {+ hitAttrViews := map[string]bool{}+ for _, blockID := range blockIDs {+ tree := trees[blockID]+ if nil == tree {continue}- parentResult := buildSearchAttributeViewResult(avSearchTmpResults, avBlock.BlockIDs[0], trees, excludeAvIDs)- if nil == parentResult {+ node := treenode.GetNodeInTree(tree, blockID)+ if nil == node || "" == node.AttributeViewID {continue}- ret = append(ret, parentResult)- for _, blockID := range avBlock.BlockIDs {- result := buildSearchAttributeViewResult(avSearchTmpResults, blockID, trees, excludeAvIDs)- if nil != result {- parentResult.Children = append(parentResult.Children, result)++ avID := node.AttributeViewID+ var existAv *AvSearchTempResult+ for _, tmpResult := range avSearchTmpResults {+ if tmpResult.AvID == avID {+ existAv = tmpResult+ break}}- }- return-}--func buildSearchAttributeViewResult(avSearchTempResults []*AvSearchTempResult, blockID string, trees map[string]*parse.Tree, excludeAvIDs []string) (ret *AvSearchResult) {- tree := trees[blockID]- if nil == tree {- return- }-- node := treenode.GetNodeInTree(tree, blockID)- if nil == node {- return- }+ if nil == existAv || gulu.Str.Contains(avID, excludeAvIDs) {+ continue+ }- if "" == node.AttributeViewID {- return- }+ if hitAttrViews[avID] {+ continue+ }+ hitAttrViews[avID] = true- avID := node.AttributeViewID- var existAv *AvSearchTempResult- for _, tmpResult := range avSearchTempResults {- if tmpResult.AvID == avID {- existAv = tmpResult- break+ attrView, _ := av.ParseAttributeView(avID)+ if nil == attrView {+ continue}- }- if nil == existAv {- return- }- attrView, _ := av.ParseAttributeView(avID)- if nil == attrView {- return- }- viewID := node.IALAttr(av.NodeAttrView)- if "" == viewID {- viewID = attrView.ViewID- }- view, _ := attrView.GetCurrentView(viewID)- if nil == view {- return- }+ var hPath string+ baseBlock := treenode.GetBlockTreeRootByPath(node.Box, node.Path)+ if nil != baseBlock {+ hPath = baseBlock.HPath+ }+ box := Conf.Box(node.Box)+ if nil != box {+ hPath = box.Name + hPath+ }- var hPath string- baseBlock := treenode.GetBlockTreeRootByPath(node.Box, node.Path)- if nil != baseBlock {- hPath = baseBlock.HPath- }- box := Conf.Box(node.Box)- if nil != box {- hPath = box.Name + hPath- }+ name := existAv.AvName+ if "" == name {+ name = Conf.language(267)+ }- name := existAv.AvName- if "" == name {- name = Conf.language(267)- }+ parent := &AvSearchResult{+ AvID: avID,+ AvName: existAv.AvName,+ BlockID: blockID,+ HPath: hPath,+ }+ ret = append(ret, parent)- if !gulu.Str.Contains(avID, excludeAvIDs) {- ret = &AvSearchResult{- AvID: avID,- AvName: existAv.AvName,- ViewName: view.Name,- BlockID: blockID,- HPath: hPath,+ for _, view := range attrView.Views {+ child := &AvSearchResult{+ AvID: avID,+ AvName: existAv.AvName,+ ViewName: view.Name,+ ViewID: view.ID,+ BlockID: blockID,+ HPath: hPath,+ }+ parent.Children = append(parent.Children, child)}}returndiff --git a/kernel/treenode/av.go b/kernel/treenode/av.goindex 1b1449e21b..4c6492a7c5 100644--- a/kernel/treenode/av.go+++ b/kernel/treenode/av.go@@ -55,50 +55,3 @@ func GetMirrorAttrViewBlockIDs(avID string) (ret []string) {}return}--type AvBlock struct {- AvID string- BlockIDs []string-}--func BatchGetMirrorAttrViewBlocks(avIDs []string) (ret []*AvBlock) {- av.AttributeViewBlocksLock.Lock()- defer av.AttributeViewBlocksLock.Unlock()-- ret = []*AvBlock{}-- blocks := filepath.Join(util.DataDir, "storage", "av", "blocks.msgpack")- if !filelock.IsExist(blocks) {- return- }-- data, err := filelock.ReadFile(blocks)- if err != nil {- logging.LogErrorf("read attribute view blocks failed: %s", err)- return- }-- avBlocks := map[string][]string{}- if err = msgpack.Unmarshal(data, &avBlocks); err != nil {- logging.LogErrorf("unmarshal attribute view blocks failed: %s", err)- return- }-- for _, avID := range avIDs {- var blockIDs []string- bts := GetBlockTrees(avBlocks[avID])- for blockID := range bts {- blockIDs = append(blockIDs, blockID)- }- if 1 > len(blockIDs) {- continue- }-- avBlock := &AvBlock{- AvID: avID,- BlockIDs: blockIDs,- }- ret = append(ret, avBlock)- }- return-}