🐛 Abnormal sorting of database relation fields https://github.com/siyuan-note/siyuan/issues/10835

This commit is contained in:
Daniel 2024-04-03 10:54:23 +08:00
parent 5e95593f51
commit eae61fd4a7
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
4 changed files with 16 additions and 14 deletions

View file

@ -420,7 +420,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
} }
if 0 == v.UpdatedAt { if 0 == v.UpdatedAt {
v.UpdatedAt = v.CreatedAt v.UpdatedAt = v.CreatedAt + 1000
} }
} }
} }

View file

@ -57,6 +57,13 @@ type Value struct {
Rollup *ValueRollup `json:"rollup,omitempty"` Rollup *ValueRollup `json:"rollup,omitempty"`
} }
func (value *Value) SetUpdatedAt(mills int64) {
value.UpdatedAt = mills
if value.CreatedAt == value.UpdatedAt {
value.UpdatedAt += 1000 // 防止更新时间和创建时间一样
}
}
func (value *Value) String() string { func (value *Value) String() string {
if nil == value { if nil == value {
return "" return ""
@ -198,9 +205,8 @@ func (value *Value) IsEdited() bool {
return true return true
} }
if value.IsEmpty() { if !value.IsEmpty() {
// 空数据认为是未编辑过的 return true
return false
} }
return value.CreatedAt != value.UpdatedAt return value.CreatedAt != value.UpdatedAt
} }

View file

@ -687,7 +687,7 @@ func renderAttributeView(attrView *av.AttributeView, viewID, query string, page,
} }
if 0 == v.UpdatedAt { if 0 == v.UpdatedAt {
v.UpdatedAt = v.CreatedAt v.UpdatedAt = v.CreatedAt + 1000
} }
} }
} }
@ -2913,18 +2913,12 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
if nil != blockVal { if nil != blockVal {
blockVal.Block.Updated = now blockVal.Block.Updated = now
blockVal.UpdatedAt = now blockVal.SetUpdatedAt(now)
if val.CreatedAt == val.UpdatedAt {
val.UpdatedAt += 1000 // 防止更新时间和创建时间一样
}
if isUpdatingBlockKey { if isUpdatingBlockKey {
blockVal.IsDetached = val.IsDetached blockVal.IsDetached = val.IsDetached
} }
} }
val.UpdatedAt = now val.SetUpdatedAt(now)
if val.CreatedAt == val.UpdatedAt {
val.UpdatedAt += 1000 // 防止更新时间和创建时间一样
}
key, _ := attrView.GetKey(val.KeyID) key, _ := attrView.GetKey(val.KeyID)
if nil != key && av.KeyTypeRelation == key.Type && nil != key.Relation { if nil != key && av.KeyTypeRelation == key.Type && nil != key.Relation {
@ -2956,6 +2950,7 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, rowID) destVal.Relation.BlockIDs = append(destVal.Relation.BlockIDs, rowID)
destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs) destVal.Relation.BlockIDs = gulu.Str.RemoveDuplicatedElem(destVal.Relation.BlockIDs)
destVal.SetUpdatedAt(now)
break break
} }
} }
@ -2974,6 +2969,7 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
for _, value := range keyValues.Values { for _, value := range keyValues.Values {
if value.BlockID == blockID { if value.BlockID == blockID {
value.Relation.BlockIDs = gulu.Str.RemoveElem(value.Relation.BlockIDs, rowID) value.Relation.BlockIDs = gulu.Str.RemoveElem(value.Relation.BlockIDs, rowID)
value.SetUpdatedAt(now)
break break
} }
} }

View file

@ -995,7 +995,7 @@ func GetAttributeViewDefaultValue(valueID, keyID, blockID string, typ av.KeyType
ret.CreatedAt = time.Now().UnixMilli() ret.CreatedAt = time.Now().UnixMilli()
} }
if 0 == ret.UpdatedAt { if 0 == ret.UpdatedAt {
ret.UpdatedAt = ret.CreatedAt ret.UpdatedAt = ret.CreatedAt + 1000
} }
switch typ { switch typ {