From 99cf9874654905cd63813b4fb271844fd3665598 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 28 Jul 2025 23:10:11 +0800 Subject: [PATCH] :art: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964 --- kernel/model/attribute_view.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 1a7e97f8d..5cdee4eb9 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -3030,6 +3030,24 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a } else { v.ItemIDs = append([]string{addingBlockID}, v.ItemIDs...) } + + for _, g := range v.Groups { + if "" != previousBlockID { + changed := false + for i, id := range g.GroupItemIDs { + if id == previousBlockID { + g.GroupItemIDs = append(g.GroupItemIDs[:i+1], append([]string{addingBlockID}, g.GroupItemIDs[i+1:]...)...) + changed = true + break + } + } + if !changed { + g.GroupItemIDs = append(g.GroupItemIDs, addingBlockID) + } + } else { + g.GroupItemIDs = append([]string{addingBlockID}, g.GroupItemIDs...) + } + } } // 如果存在分组条件,则将分组条件应用到新添加的块上 @@ -3159,7 +3177,7 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er for _, groupView := range view.Groups { for _, blockID := range srcIDs { - groupView.ItemIDs = gulu.Str.RemoveElem(groupView.ItemIDs, blockID) + groupView.GroupItemIDs = gulu.Str.RemoveElem(groupView.GroupItemIDs, blockID) } } }