An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Add "Show unique values" to the calculation of the database rollup field https://github.com/siyuan-note/siyuan/issues/15852
Daniel1344859c1e3e
diff --git a/kernel/av/calc.go b/kernel/av/calc.goindex 77d53bacee..dab4134ef6 100644--- a/kernel/av/calc.go+++ b/kernel/av/calc.go@@ -1710,9 +1710,35 @@ func calcFieldRollup(collection Collection, field Field, fieldIndex int) {values := item.GetValues()if nil != values[fieldIndex] && nil != values[fieldIndex].Rollup {for _, content := range values[fieldIndex].Rollup.Contents {- if !uniqueValues[content.String(true)] {- uniqueValues[content.String(true)] = true- countUniqueValues+++ switch content.Type {+ case KeyTypeRelation:+ for _, relationVal := range content.Relation.Contents {+ key := relationVal.String(true)+ if !uniqueValues[key] {+ uniqueValues[key] = true+ countUniqueValues+++ }+ }+ case KeyTypeMSelect:+ for _, mSelectVal := range content.MSelect {+ if !uniqueValues[mSelectVal.Content] {+ uniqueValues[mSelectVal.Content] = true+ countUniqueValues+++ }+ }+ case KeyTypeMAsset:+ for _, mAssetVal := range content.MAsset {+ if !uniqueValues[mAssetVal.Content] {+ uniqueValues[mAssetVal.Content] = true+ countUniqueValues+++ }+ }+ default:+ key := content.String(true)+ if !uniqueValues[key] {+ uniqueValues[key] = true+ countUniqueValues+++ }}}}diff --git a/kernel/av/value.go b/kernel/av/value.goindex 32ce554d50..781b5720c3 100644--- a/kernel/av/value.go+++ b/kernel/av/value.go@@ -835,16 +835,39 @@ func (r *ValueRollup) calcContents(calc *RollupCalc, destKey *Key) {switch calc.Operator {case CalcOperatorNone:case CalcOperatorUniqueValues:- var newContents []*ValueuniqueValues := map[string]bool{}- for _, v := range r.Contents {- key := v.String(true)- if !uniqueValues[key] {- uniqueValues[key] = true- newContents = append(newContents, v)+ for _, content := range r.Contents {+ switch content.Type {+ case KeyTypeRelation:+ var newRelationContents []*Value+ for _, relationVal := range content.Relation.Contents {+ key := relationVal.String(true)+ if !uniqueValues[key] {+ uniqueValues[key] = true+ newRelationContents = append(newRelationContents, relationVal)+ }+ }+ content.Relation.Contents = newRelationContents+ case KeyTypeMSelect:+ var newMSelect []*ValueSelect+ for _, mSelect := range content.MSelect {+ if !uniqueValues[mSelect.Content] {+ uniqueValues[mSelect.Content] = true+ newMSelect = append(newMSelect, mSelect)+ }+ }+ content.MSelect = newMSelect+ case KeyTypeMAsset:+ var newMAsset []*ValueAsset+ for _, mAsset := range content.MAsset {+ if !uniqueValues[mAsset.Content] {+ uniqueValues[mAsset.Content] = true+ newMAsset = append(newMAsset, mAsset)+ }+ }+ content.MAsset = newMAsset}}- r.Contents = newContentscase CalcOperatorCountAll:r.Contents = []*Value{{Type: KeyTypeNumber, Number: NewFormattedValueNumber(float64(len(r.Contents)), NumberFormatNone)}}case CalcOperatorCountValues: