An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Database multi-field sorting fails Fix https://github.com/siyuan-note/siyuan/issues/10616
Daniel0daa752ba9d5
diff --git a/kernel/av/sort.go b/kernel/av/sort.goindex fef2cd9ed2..ade93d63f9 100644--- a/kernel/av/sort.go+++ b/kernel/av/sort.go@@ -44,19 +44,11 @@ func (value *Value) Compare(other *Value) int {switch value.Type {case KeyTypeBlock:if nil != value.Block && nil != other.Block {- ret := strings.Compare(value.Block.Content, other.Block.Content)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(value.Block.Content, other.Block.Content)}case KeyTypeText:if nil != value.Text && nil != other.Text {- ret := strings.Compare(value.Text.Content, other.Text.Content)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(value.Text.Content, other.Text.Content)}case KeyTypeNumber:if nil != value.Number && nil != other.Number {@@ -67,16 +59,16 @@ func (value *Value) Compare(other *Value) int {if value.Number.Content > other.Number.Content {return 1- } else if value.Number.Content < other.Number.Content {+ }+ if value.Number.Content < other.Number.Content {return -1- } else {- return int(value.CreatedAt - other.CreatedAt)}+ return 0} else {if other.Number.IsNotEmpty {return -1}- return int(value.CreatedAt - other.CreatedAt)+ return 0}}case KeyTypeDate:@@ -87,37 +79,37 @@ func (value *Value) Compare(other *Value) int {}if value.Date.Content > other.Date.Content {return 1- } else if value.Date.Content < other.Date.Content {+ }+ if value.Date.Content < other.Date.Content {return -1- } else {- return int(value.CreatedAt - other.CreatedAt)}+ return 0} else {if other.Date.IsNotEmpty {return -1}- return int(value.CreatedAt - other.CreatedAt)+ return 0}}case KeyTypeCreated:if nil != value.Created && nil != other.Created {if value.Created.Content > other.Created.Content {return 1- } else if value.Created.Content < other.Created.Content {+ }+ if value.Created.Content < other.Created.Content {return -1- } else {- return int(value.CreatedAt - other.CreatedAt)}+ return 0}case KeyTypeUpdated:if nil != value.Updated && nil != other.Updated {if value.Updated.Content > other.Updated.Content {return 1- } else if value.Updated.Content < other.Updated.Content {+ }+ if value.Updated.Content < other.Updated.Content {return -1- } else {- return int(value.CreatedAt - other.CreatedAt)}+ return 0}case KeyTypeSelect, KeyTypeMSelect:if nil != value.MSelect && nil != other.MSelect {@@ -129,35 +121,19 @@ func (value *Value) Compare(other *Value) int {for _, v := range other.MSelect {v2 += v.Content}- ret := strings.Compare(v1, v2)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(v1, v2)}case KeyTypeURL:if nil != value.URL && nil != other.URL {- ret := strings.Compare(value.URL.Content, other.URL.Content)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(value.URL.Content, other.URL.Content)}case KeyTypeEmail:if nil != value.Email && nil != other.Email {- ret := strings.Compare(value.Email.Content, other.Email.Content)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(value.Email.Content, other.Email.Content)}case KeyTypePhone:if nil != value.Phone && nil != other.Phone {- ret := strings.Compare(value.Phone.Content, other.Phone.Content)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(value.Phone.Content, other.Phone.Content)}case KeyTypeMAsset:if nil != value.MAsset && nil != other.MAsset {@@ -169,11 +145,7 @@ func (value *Value) Compare(other *Value) int {for _, v := range other.MAsset {v2 += v.Content}- ret := strings.Compare(v1, v2)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(v1, v2)}case KeyTypeTemplate:if nil != value.Template && nil != other.Template {@@ -188,13 +160,9 @@ func (value *Value) Compare(other *Value) int {if v1 < v2 {return -1}- return int(value.CreatedAt - other.CreatedAt)- }- ret := strings.Compare(value.Template.Content, other.Template.Content)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)+ return 0}- return ret+ return strings.Compare(value.Template.Content, other.Template.Content)}case KeyTypeCheckbox:if nil != value.Checkbox && nil != other.Checkbox {@@ -204,7 +172,7 @@ func (value *Value) Compare(other *Value) int {if !value.Checkbox.Checked && other.Checkbox.Checked {return -1}- return int(value.CreatedAt - other.CreatedAt)+ return 0}case KeyTypeRelation:if nil != value.Relation && nil != other.Relation {@@ -231,13 +199,9 @@ func (value *Value) Compare(other *Value) int {if v1 < v2 {return -1}- return int(value.CreatedAt - other.CreatedAt)+ return 0}- ret := strings.Compare(vContent, oContent)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)- }- return ret+ return strings.Compare(vContent, oContent)}case KeyTypeRollup:if nil != value.Rollup && nil != other.Rollup {@@ -263,14 +227,10 @@ func (value *Value) Compare(other *Value) int {if v1 < v2 {return -1}- return int(value.CreatedAt - other.CreatedAt)- }- ret := strings.Compare(vContent, oContent)- if 0 == ret {- ret = int(value.CreatedAt - other.CreatedAt)+ return 0}- return ret+ return strings.Compare(vContent, oContent)}}- return int(value.CreatedAt - other.CreatedAt)+ return 0}diff --git a/kernel/av/table.go b/kernel/av/table.goindex 10fcbf369e..1a57055dc9 100644--- a/kernel/av/table.go+++ b/kernel/av/table.go@@ -208,6 +208,7 @@ func (table *Table) SortRows() {})sort.Slice(editedRows, func(i, j int) bool {+ sorted := truefor _, colIndexSort := range colIndexSorts {val1 := editedRows[i].Cells[colIndexSort.Index].Valueif nil == val1 {@@ -221,14 +222,28 @@ func (table *Table) SortRows() {result := val1.Compare(val2)if 0 == result {+ sorted = falsecontinue}+ sorted = trueif colIndexSort.Order == SortOrderAsc {return 0 > result}return 0 < result}++ if !sorted {+ key1 := editedRows[i].GetBlockValue()+ if nil == key1 {+ return false+ }+ key2 := editedRows[j].GetBlockValue()+ if nil == key2 {+ return false+ }+ return key1.CreatedAt < key2.CreatedAt+ }return false})