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

Daniel7787ac6e1dbf
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 0616dba488..4a8c8285f5 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -44,6 +44,51 @@ import (
"github.com/xrash/smetrics"
)
+func (tx *Transaction) doSortAttrViewGroup(operation *Operation) (ret *TxErr) {
+ if err := sortAttributeViewGroup(operation.AvID, operation.BlockID, operation.PreviousID, operation.ID); nil != err {
+ return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
+ }
+ return
+}
+
+func sortAttributeViewGroup(avID, blockID, previousGroupID, groupID string) (err error) {
+ attrView, err := av.ParseAttributeView(avID)
+ if err != nil {
+ logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
+ return
+ }
+
+ view, err := getAttrViewViewByBlockID(attrView, blockID)
+ if err != nil {
+ return err
+ }
+
+ var group *av.View
+ var index, previousIndex int
+ for i, g := range view.Groups {
+ if g.ID == groupID {
+ group = g
+ index = i
+ break
+ }
+ }
+ if nil == group {
+ return
+ }
+
+ view.Groups = append(view.Groups[:index], view.Groups[index+1:]...)
+ for i, g := range group.Groups {
+ if g.ID == previousGroupID {
+ previousIndex = i + 1
+ break
+ }
+ }
+ view.Groups = util.InsertElem(view.Groups, previousIndex, group)
+
+ err = av.SaveAttributeView(attrView)
+ return
+}
+
func (tx *Transaction) doRemoveAttrViewGroup(operation *Operation) (ret *TxErr) {
if err := removeAttributeViewGroup(operation.AvID, operation.BlockID); nil != err {
return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
@@ -2134,9 +2179,6 @@ func (tx *Transaction) doSortAttrViewView(operation *Operation) (ret *TxErr) {
break
}
}
- if nil == view {
- return
- }
attrView.Views = append(attrView.Views[:index], attrView.Views[index+1:]...)
for i, v := range attrView.Views {
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 89fec18261..c482730215 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -305,6 +305,8 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doSyncAttrViewTableColWidth(op)
case "removeAttrViewGroup":
ret = tx.doRemoveAttrViewGroup(op)
+ case "sortAttrViewGroup":
+ ret = tx.doSortAttrViewGroup(op)
}
if nil != ret {