🐛 Database filtering for specific dates not working Fix https://github.com/siyuan-note/siyuan/issues/10518

This commit is contained in:
Daniel 2024-03-08 10:30:41 +08:00
parent a46e626319
commit b7e3e5fd8d
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 66 additions and 31 deletions

View file

@ -77,12 +77,8 @@ const (
func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value) (ret *Value) {
if nil != filter.Value {
if filter.Value.IsGenerated() {
// 自动生成类型的过滤条件不设置默认值
return nil
}
if KeyTypeRelation == filter.Value.Type {
// 关联类型的过滤条件不设置默认值 https://ld246.com/article/1709608533749
if KeyTypeRelation == filter.Value.Type || KeyTypeTemplate == filter.Value.Type || KeyTypeRollup == filter.Value.Type || KeyTypeUpdated == filter.Value.Type || KeyTypeCreated == filter.Value.Type {
// 所有生成的数据都不设置默认值
return nil
}
}

View file

@ -86,11 +86,19 @@ func (value *Value) Compare(other *Value) int {
switch value.Type {
case KeyTypeBlock:
if nil != value.Block && nil != other.Block {
return strings.Compare(value.Block.Content, other.Block.Content)
ret := strings.Compare(value.Block.Content, other.Block.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeText:
if nil != value.Text && nil != other.Text {
return strings.Compare(value.Text.Content, other.Text.Content)
ret := strings.Compare(value.Text.Content, other.Text.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeNumber:
if nil != value.Number && nil != other.Number {
@ -104,7 +112,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Number.Content < other.Number.Content {
return -1
} else {
return 0
return int(value.CreatedAt - other.CreatedAt)
}
} else {
if other.Number.IsNotEmpty {
@ -124,7 +132,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Date.Content < other.Date.Content {
return -1
} else {
return 0
return int(value.CreatedAt - other.CreatedAt)
}
} else {
if other.Date.IsNotEmpty {
@ -140,7 +148,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Created.Content < other.Created.Content {
return -1
} else {
return 0
return int(value.CreatedAt - other.CreatedAt)
}
}
case KeyTypeUpdated:
@ -150,7 +158,7 @@ func (value *Value) Compare(other *Value) int {
} else if value.Updated.Content < other.Updated.Content {
return -1
} else {
return 0
return int(value.CreatedAt - other.CreatedAt)
}
}
case KeyTypeSelect, KeyTypeMSelect:
@ -163,19 +171,35 @@ func (value *Value) Compare(other *Value) int {
for _, v := range other.MSelect {
v2 += v.Content
}
return strings.Compare(v1, v2)
ret := strings.Compare(v1, v2)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeURL:
if nil != value.URL && nil != other.URL {
return strings.Compare(value.URL.Content, other.URL.Content)
ret := strings.Compare(value.URL.Content, other.URL.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeEmail:
if nil != value.Email && nil != other.Email {
return strings.Compare(value.Email.Content, other.Email.Content)
ret := strings.Compare(value.Email.Content, other.Email.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypePhone:
if nil != value.Phone && nil != other.Phone {
return strings.Compare(value.Phone.Content, other.Phone.Content)
ret := strings.Compare(value.Phone.Content, other.Phone.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeMAsset:
if nil != value.MAsset && nil != other.MAsset {
@ -187,7 +211,11 @@ func (value *Value) Compare(other *Value) int {
for _, v := range other.MAsset {
v2 += v.Content
}
return strings.Compare(v1, v2)
ret := strings.Compare(v1, v2)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeTemplate:
if nil != value.Template && nil != other.Template {
@ -199,13 +227,16 @@ func (value *Value) Compare(other *Value) int {
if v1 > v2 {
return 1
}
if v1 < v2 {
return -1
}
return 0
return int(value.CreatedAt - other.CreatedAt)
}
return strings.Compare(value.Template.Content, other.Template.Content)
ret := strings.Compare(value.Template.Content, other.Template.Content)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeCheckbox:
if nil != value.Checkbox && nil != other.Checkbox {
@ -215,7 +246,7 @@ func (value *Value) Compare(other *Value) int {
if !value.Checkbox.Checked && other.Checkbox.Checked {
return -1
}
return 0
return int(value.CreatedAt - other.CreatedAt)
}
case KeyTypeRelation:
if nil != value.Relation && nil != other.Relation {
@ -242,9 +273,13 @@ func (value *Value) Compare(other *Value) int {
if v1 < v2 {
return -1
}
return 0
return int(value.CreatedAt - other.CreatedAt)
}
return strings.Compare(vContent, oContent)
ret := strings.Compare(vContent, oContent)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
case KeyTypeRollup:
if nil != value.Rollup && nil != other.Rollup {
@ -267,13 +302,16 @@ func (value *Value) Compare(other *Value) int {
if v1 > v2 {
return 1
}
if v1 < v2 {
return -1
}
return 0
return int(value.CreatedAt - other.CreatedAt)
}
return strings.Compare(vContent, oContent)
ret := strings.Compare(vContent, oContent)
if 0 == ret {
ret = int(value.CreatedAt - other.CreatedAt)
}
return ret
}
}
return int(value.CreatedAt - other.CreatedAt)

View file

@ -193,8 +193,7 @@ func (value *Value) IsEdited() bool {
return true
}
if value.IsGenerated() {
// 所有生成的数据都认为是编辑过的
if KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type {
return true
}
@ -206,7 +205,7 @@ func (value *Value) IsEdited() bool {
}
func (value *Value) IsGenerated() bool {
return KeyTypeTemplate == value.Type || KeyTypeRollup == value.Type || KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type
return KeyTypeUpdated == value.Type || KeyTypeCreated == value.Type
}
func (value *Value) IsEmpty() bool {

View file

@ -1007,7 +1007,7 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
for _, blockID := range relVal.Relation.BlockIDs {
destVal := destAv.GetValue(rollupKey.Rollup.KeyID, blockID)
if nil == destVal {
destVal = treenode.GetAttributeViewDefaultValue(ast.NewNodeID(), rollupKey.Rollup.KeyID, blockID, destKey.Type)
continue
}
if av.KeyTypeNumber == destKey.Type {
destVal.Number.Format = destKey.NumberFormat
@ -1034,7 +1034,9 @@ func renderAttributeViewTable(attrView *av.AttributeView, view *av.View) (ret *a
blocks[blockValue.BlockID] = blockValue
}
for _, blockID := range cell.Value.Relation.BlockIDs {
cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, blocks[blockID])
if val := blocks[blockID]; nil != val {
cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, val)
}
}
}
}