An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Register every imported database relation target https://github.com/siyuan-note/siyuan/issues/20957
Danielc88e82277dec
diff --git a/kernel/model/import.go b/kernel/model/import.goindex f72d6399eb..c5dae4d5df 100644--- a/kernel/model/import.go+++ b/kernel/model/import.go@@ -886,7 +886,6 @@ func importSY0(zipPath, boxID, toPath string, createNotebook, autoDetect bool, supdateBoundBlockAvsAttribute(attrViewIDs, avBoxID)// 插入关联关系 https://github.com/siyuan-note/siyuan/issues/11628- relationAvs := map[string]string{}for _, avID := range avIDs {attrView, _ := av.ParseAttributeView(avID)if nil == attrView {@@ -894,15 +893,11 @@ func importSY0(zipPath, boxID, toPath string, createNotebook, autoDetect bool, s}for _, keyValues := range attrView.KeyValues {- if nil != keyValues.Key && av.KeyTypeRelation == keyValues.Key.Type && nil != keyValues.Key.Relation {- relationAvs[avID] = keyValues.Key.Relation.AvID+ if nil != keyValues.Key && av.KeyTypeRelation == keyValues.Key.Type && nil != keyValues.Key.Relation && keyValues.Key.Relation.AvID != "" {+ av.UpsertAvBackRel(avID, keyValues.Key.Relation.AvID)}}}-- for srcAvID, destAvID := range relationAvs {- av.UpsertAvBackRel(srcAvID, destAvID)- }}// 普通笔记本将关联的闪卡数据合并到默认卡包 data/storage/riff/20230218211946-2kw8jgx 中diff --git a/kernel/model/import_attribute_view_fts5_test.go b/kernel/model/import_attribute_view_fts5_test.goindex 7ea890e554..01e4cc89e0 100644--- a/kernel/model/import_attribute_view_fts5_test.go+++ b/kernel/model/import_attribute_view_fts5_test.go@@ -8,6 +8,7 @@ import ("encoding/json""os""path/filepath"+ "slices""strings""testing"@@ -90,6 +91,21 @@ func TestImportSYAttributeViewBindingIsolation(t *testing.T) {source.Root.SetIALAttr(av.NodeAttrNameAvs, avID)writeExportRelatedTestTree(t, source)attrView := av.NewAttributeView(avID)+ relationTargets := []*av.AttributeView{av.NewAttributeView(ast.NewNodeID()), av.NewAttributeView(ast.NewNodeID())}+ archiveEntries := map[string][]byte{}+ for _, target := range relationTargets {+ key := av.NewKey(ast.NewNodeID(), "Related", "", av.KeyTypeRelation)+ key.Relation = &av.Relation{AvID: target.ID}+ attrView.KeyValues = append(attrView.KeyValues, &av.KeyValues{Key: key})+ if err := av.SaveAttributeView(target); err != nil {+ t.Fatal(err)+ }+ data, err := json.Marshal(target)+ if err != nil {+ t.Fatal(err)+ }+ archiveEntries["Daily/storage/av/"+target.ID+".json"] = data+ }values := attrView.GetBlockKeyValues()for i, id := range []string{externalID, docID} {itemID := ast.NewNodeID()@@ -114,7 +130,9 @@ func TestImportSYAttributeViewBindingIsolation(t *testing.T) {t.Fatal(err)}writer := zip.NewWriter(archive)- for path, data := range map[string][]byte{"Daily/" + docID + ".sy": docData, "Daily/storage/av/" + avID + ".json": avData} {+ archiveEntries["Daily/"+docID+".sy"] = docData+ archiveEntries["Daily/storage/av/"+avID+".json"] = avData+ for path, data := range archiveEntries {entry, createErr := writer.Create(path)if createErr != nil {t.Fatal(createErr)@@ -159,6 +177,27 @@ func TestImportSYAttributeViewBindingIsolation(t *testing.T) {if err != nil {t.Fatal(err)}+ relationCount := 0+ for _, kv := range imported.KeyValues {+ if kv.Key.Type != av.KeyTypeRelation {+ continue+ }+ relationCount+++ targetID := kv.Key.Relation.AvID+ t.Cleanup(func() { av.SetAVBoxID(targetID, "") })+ if targetID == relationTargets[0].ID || targetID == relationTargets[1].ID {+ t.Fatal("relation target ID was not remapped")+ }+ if _, err := av.ParseAttributeViewInBox(targetID, avBoxID); err != nil {+ t.Fatal(err)+ }+ if !slices.Contains(av.GetSrcAvIDs(targetID), newAvID) {+ t.Fatalf("import omitted relation dependency %s -> %s", newAvID, targetID)+ }+ }+ if relationCount != 2 {+ t.Fatalf("imported %d relation fields, want 2", relationCount)+ }rows := imported.GetBlockKeyValues().Valuesif len(rows) != 2 || rows[0].IsDetached != encrypted || rows[1].IsDetached || rows[1].Block.ID != newDocID ||rows[0].Block.Content != "External" || rows[0].BlockID != values.Values[0].BlockID {