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 1/3] :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 中 From 06993bddd5c92ba0a6f2aa058cafd1fba4e772fd Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 3 Jun 2024 11:19:33 +0800 Subject: [PATCH 2/3] :bug: In some cases, the primary key sorting of the database panel fails https://github.com/siyuan-note/siyuan/issues/11621 --- kernel/model/attribute_view.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index f5e770581..f4f3c7c02 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -2449,12 +2449,25 @@ func SortAttributeViewKey(avID, keyID, previousKeyID string) (err error) { return } - if 1 > len(attrView.KeyIDs) { - for _, keyValues := range attrView.KeyValues { - attrView.KeyIDs = append(attrView.KeyIDs, keyValues.Key.ID) + existKeyIDs := map[string]bool{} + for _, keyValues := range attrView.KeyValues { + existKeyIDs[keyValues.Key.ID] = true + } + + for k, _ := range existKeyIDs { + if !gulu.Str.Contains(k, attrView.KeyIDs) { + attrView.KeyIDs = append(attrView.KeyIDs, k) } } + var tmp []string + for _, k := range attrView.KeyIDs { + if ok := existKeyIDs[k]; ok { + tmp = append(tmp, k) + } + } + attrView.KeyIDs = tmp + var currentKeyID string var idx, previousIndex int for i, k := range attrView.KeyIDs { From 02fe7b966ccd248ad771f8b9fcc6ffa9f0e933dc Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 3 Jun 2024 11:35:43 +0800 Subject: [PATCH 3/3] :bug: In some cases, the primary key sorting of the database panel fails https://github.com/siyuan-note/siyuan/issues/11621 --- kernel/model/attribute_view.go | 43 ++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index f4f3c7c02..e16ee3ffd 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -649,6 +649,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) { } // 字段排序 + refreshAttrViewKeyIDs(attrView) sorts := map[string]int{} for i, k := range attrView.KeyIDs { sorts[k] = i @@ -2449,24 +2450,7 @@ func SortAttributeViewKey(avID, keyID, previousKeyID string) (err error) { return } - existKeyIDs := map[string]bool{} - for _, keyValues := range attrView.KeyValues { - existKeyIDs[keyValues.Key.ID] = true - } - - for k, _ := range existKeyIDs { - if !gulu.Str.Contains(k, attrView.KeyIDs) { - attrView.KeyIDs = append(attrView.KeyIDs, k) - } - } - - var tmp []string - for _, k := range attrView.KeyIDs { - if ok := existKeyIDs[k]; ok { - tmp = append(tmp, k) - } - } - attrView.KeyIDs = tmp + refreshAttrViewKeyIDs(attrView) var currentKeyID string var idx, previousIndex int @@ -2495,6 +2479,29 @@ func SortAttributeViewKey(avID, keyID, previousKeyID string) (err error) { return } +func refreshAttrViewKeyIDs(attrView *av.AttributeView) { + // 订正 keyIDs 数据 + + existKeyIDs := map[string]bool{} + for _, keyValues := range attrView.KeyValues { + existKeyIDs[keyValues.Key.ID] = true + } + + for k, _ := range existKeyIDs { + if !gulu.Str.Contains(k, attrView.KeyIDs) { + attrView.KeyIDs = append(attrView.KeyIDs, k) + } + } + + var tmp []string + for _, k := range attrView.KeyIDs { + if ok := existKeyIDs[k]; ok { + tmp = append(tmp, k) + } + } + attrView.KeyIDs = tmp +} + func (tx *Transaction) doAddAttrViewColumn(operation *Operation) (ret *TxErr) { var icon string if nil != operation.Data {