Skip to content

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

:art: Database grouping by field https://github.com/siyuan-note/siyuan/issues/10964

Danield0662b5fde19
diff --git a/kernel/av/av.go b/kernel/av/av.go
index a575ab446d..5f9ea004bb 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -220,6 +220,21 @@ func (view *View) GetGroup(groupID string) *View {
return nil
}
+// GetGroupKey 获取分组视图的分组字段。
+func (view *View) GetGroupKey(attrView *AttributeView) (ret *Key) {
+ if nil == view.Group || "" == view.Group.Field {
+ return
+ }
+
+ for _, kv := range attrView.KeyValues {
+ if kv.Key.ID == view.Group.Field {
+ ret = kv.Key
+ return
+ }
+ }
+ return
+}
+
// GroupCalc 描述了分组计算规则和结果的结构。
type GroupCalc struct {
Field string `json:"field"` // 字段 ID
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 026361fcfc..f9d9152c96 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -3063,7 +3063,7 @@ func addAttributeViewBlock(now int64, avID, blockID, groupID, previousBlockID, a
}
// 如果存在分组条件,则将分组条件应用到新添加的块上
- groupKey := getViewGroupKey(view, attrView)
+ groupKey := view.GetGroupKey(attrView)
if nil != view && nil != groupKey {
if !filterKeyIDs[groupKey.ID] /* 过滤条件应用过的话就不重复处理了 */ && "" != groupID {
if groupView := view.GetGroup(groupID); nil != groupView {
@@ -3868,6 +3868,7 @@ func updateAttributeViewColTemplate(operation *Operation) (err error) {
}
}
+ regenAttrViewViewGroups(attrView, operation.ID)
err = av.SaveAttributeView(attrView)
return
}
@@ -4524,7 +4525,7 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
func regenAttrViewViewGroups(attrView *av.AttributeView, keyID string) {
for _, view := range attrView.Views {
- groupKey := getViewGroupKey(view, attrView)
+ groupKey := view.GetGroupKey(attrView)
if nil == groupKey {
continue
}
@@ -4549,17 +4550,6 @@ func regenAttrViewViewGroups(attrView *av.AttributeView, keyID string) {
}
}
-func getViewGroupKey(view *av.View, attrView *av.AttributeView) *av.Key {
- if nil == view.Group {
- return nil
- }
- if "" == view.Group.Field {
- return nil
- }
- ret, _ := attrView.GetKey(view.Group.Field)
- return ret
-}
-
func unbindBlockAv(tx *Transaction, avID, blockID string) {
node, tree, err := getNodeByBlockID(tx, blockID)
if err != nil {
@@ -4753,6 +4743,7 @@ func removeAttributeViewColumnOption(operation *Operation) (err error) {
break
}
+ regenAttrViewViewGroups(attrView, operation.ID)
err = av.SaveAttributeView(attrView)
return
}