Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: The sorting of fields in the database attribute panel is unstable https://github.com/siyuan-note/siyuan/issues/12043

Daniel48162b12a63f
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 62075a389a..9f0c1769bf 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -651,7 +651,7 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
}
// 字段排序
- refreshAttrViewKeyIDs(attrView)
+ refreshAttrViewKeyIDs(attrView, true)
sorts := map[string]int{}
for i, k := range attrView.KeyIDs {
sorts[k] = i
@@ -2533,7 +2533,7 @@ func SortAttributeViewKey(avID, keyID, previousKeyID string) (err error) {
return
}
- refreshAttrViewKeyIDs(attrView)
+ refreshAttrViewKeyIDs(attrView, false)
var currentKeyID string
var idx, previousIndex int
@@ -2562,7 +2562,7 @@ func SortAttributeViewKey(avID, keyID, previousKeyID string) (err error) {
return
}
-func refreshAttrViewKeyIDs(attrView *av.AttributeView) {
+func refreshAttrViewKeyIDs(attrView *av.AttributeView, needSave bool) {
// 订正 keyIDs 数据
existKeyIDs := map[string]bool{}
@@ -2583,6 +2583,10 @@ func refreshAttrViewKeyIDs(attrView *av.AttributeView) {
}
}
attrView.KeyIDs = tmp
+
+ if needSave {
+ av.SaveAttributeView(attrView)
+ }
}
func (tx *Transaction) doAddAttrViewColumn(operation *Operation) (ret *TxErr) {