Skip to content

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

:art: Update av

Daniel919cd04c8a33
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index a2e1985c62..79a09a8afc 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -58,7 +58,6 @@ func filterRows(ret *av.AttributeView) {
}
}
}
- colIndexes = util.RemoveDuplicatedElem(colIndexes)
var rows []*av.Row
for _, row := range ret.Rows {
@@ -84,32 +83,37 @@ func filterRows(ret *av.AttributeView) {
func sortRows(ret *av.AttributeView) {
if 0 < len(ret.Sorts) {
- var colIndexes []int
+ type ColIndexSort struct {
+ Index int
+ Order av.SortOrder
+ }
+
+ var colIndexSorts []*ColIndexSort
for _, s := range ret.Sorts {
for i, c := range ret.Columns {
if c.ID == s.Column {
- colIndexes = append(colIndexes, i)
+ colIndexSorts = append(colIndexSorts, &ColIndexSort{Index: i, Order: s.Order})
break
}
}
}
- colIndexes = util.RemoveDuplicatedElem(colIndexes)
sort.Slice(ret.Rows, func(i, j int) bool {
- for _, index := range colIndexes {
- c := ret.Columns[index]
+ for _, colIndexSort := range colIndexSorts {
+ c := ret.Columns[colIndexSort.Index]
if c.Type == av.ColumnTypeBlock {
continue
}
- result := ret.Rows[i].Cells[index].Value.Compare(ret.Rows[j].Cells[index].Value)
+ result := ret.Rows[i].Cells[colIndexSort.Index].Value.Compare(ret.Rows[j].Cells[colIndexSort.Index].Value)
if 0 == result {
continue
}
- if 0 > result {
- return true
+ if colIndexSort.Order == av.SortOrderAsc {
+ return 0 > result
}
+ return 0 < result
}
return false
})
diff --git a/kernel/util/misc.go b/kernel/util/misc.go
index feb3f4fcf8..ad047e4734 100644
--- a/kernel/util/misc.go
+++ b/kernel/util/misc.go
@@ -24,18 +24,6 @@ import (
"github.com/88250/lute/html"
)
-// RemoveDuplicatedElem removes the duplicated elements from the slice.
-func RemoveDuplicatedElem(slice []int) (ret []int) {
- allKeys := make(map[int]bool)
- for _, item := range slice {
- if _, value := allKeys[item]; !value {
- allKeys[item] = true
- ret = append(ret, item)
- }
- }
- return
-}
-
// InsertElem inserts a new element value at the specified index position.
// 0 <= index <= len(a)
func InsertElem[T any](ret []T, index int, value T) []T {