Skip to content

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

:recycle: Refactor av data structure

Daniel11a55903f2f0
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 3fae15d281..dca5c7975e 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -561,6 +561,48 @@ func updateAttributeViewColumn(operation *Operation) (err error) {
return
}
+
+func (tx *Transaction) doRemoveAttrViewColumn(operation *Operation) (ret *TxErr) {
+ err := removeAttributeViewColumn(operation)
+ if nil != err {
+ return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
+ }
+ return
+}
+
+func removeAttributeViewColumn(operation *Operation) (err error) {
+ attrView, err := av.ParseAttributeView(operation.AvID)
+ if nil != err {
+ return
+ }
+
+ for i, column := range attrView.Columns {
+ if column.ID == operation.ID {
+ attrView.Columns = append(attrView.Columns[:i], attrView.Columns[i+1:]...)
+ for _, row := range attrView.Rows {
+ if len(row.Cells) <= i {
+ continue
+ }
+
+ row.Cells = append(row.Cells[:i], row.Cells[i+1:]...)
+ }
+ break
+ }
+ }
+
+ for _, view := range attrView.Views {
+ for i, column := range view.Table.Columns {
+ if column.ID == operation.ID {
+ view.Table.Columns = append(view.Table.Columns[:i], view.Table.Columns[i+1:]...)
+ break
+ }
+ }
+ }
+
+ err = av.SaveAttributeView(attrView)
+ return
+}
+
// TODO 下面的方法要重写
func (tx *Transaction) doUpdateAttrViewCell(operation *Operation) (ret *TxErr) {
@@ -652,13 +694,6 @@ func (tx *Transaction) doUpdateAttrViewColOptions(operation *Operation) (ret *Tx
return
}
-func (tx *Transaction) doRemoveAttrViewColumn(operation *Operation) (ret *TxErr) {
- err := removeAttributeViewColumn(operation.ID, operation.ParentID)
- if nil != err {
- return &TxErr{code: TxErrWriteAttributeView, id: operation.ParentID, msg: err.Error()}
- }
- return
-}
func (tx *Transaction) doSetAttrView(operation *Operation) (ret *TxErr) {
err := setAttributeView(operation)
@@ -834,30 +869,6 @@ func updateAttributeViewColumnOptions(data interface{}, id, avID string) (err er
return
}
-func removeAttributeViewColumn(columnID string, avID string) (err error) {
- attrView, err := av.ParseAttributeView(avID)
- if nil != err {
- return
- }
-
- for i, column := range attrView.Columns {
- if column.ID == columnID {
- attrView.Columns = append(attrView.Columns[:i], attrView.Columns[i+1:]...)
- for _, row := range attrView.Rows {
- if len(row.Cells) <= i {
- continue
- }
-
- row.Cells = append(row.Cells[:i], row.Cells[i+1:]...)
- }
- break
- }
- }
-
- err = av.SaveAttributeView(attrView)
- return
-}
-
func setAttributeView(operation *Operation) (err error) {
avID := operation.ID
attrViewMap, err := av.ParseAttributeViewMap(avID)
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 9dcf051bce..f84b61c697 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -237,13 +237,13 @@ func performTx(tx *Transaction) (ret *TxErr) {
ret = tx.doAddAttrViewColumn(op)
case "updateAttrViewCol":
ret = tx.doUpdateAttrViewColumn(op)
+ case "removeAttrViewCol":
+ ret = tx.doRemoveAttrViewColumn(op)
case "sortAttrViewRow":
ret = tx.doSortAttrViewRow(op)
case "sortAttrViewCol":
ret = tx.doSortAttrViewColumn(op)
// TODO 下面的方法要重写
- case "removeAttrViewCol":
- ret = tx.doRemoveAttrViewColumn(op)
case "updateAttrViewCell":
ret = tx.doUpdateAttrViewCell(op)
case "setAttrView":