From cf5ff5283a9e0ac3e38fb700ec38ef452efae2df Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 3 Jun 2024 10:13:16 +0800 Subject: [PATCH] :art: Improve database handling when importing .sy.zip https://github.com/siyuan-note/siyuan/issues/11628 --- kernel/model/import.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/kernel/model/import.go b/kernel/model/import.go index 583f06c49..6d09ed4ad 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -312,6 +312,25 @@ func ImportSY(zipPath, boxID, toPath string) (err error) { attrViewIDs = append(attrViewIDs, avID) } updateBoundBlockAvsAttribute(attrViewIDs) + + // 插入关联关系 https://github.com/siyuan-note/siyuan/issues/11628 + relationAvs := map[string]string{} + for _, avID := range avIDs { + attrView, _ := av.ParseAttributeView(avID) + if nil == attrView { + continue + } + + for _, keyValues := range attrView.KeyValues { + if nil != keyValues.Key && av.KeyTypeRelation == keyValues.Key.Type && nil != keyValues.Key.Relation { + relationAvs[avID] = keyValues.Key.Relation.AvID + } + } + } + + for srcAvID, destAvID := range relationAvs { + av.UpsertAvBackRel(srcAvID, destAvID) + } } // 将关联的闪卡数据合并到默认卡包 data/storage/riff/20230218211946-2kw8jgx 中