mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-09-22 00:20:47 +02:00
🎨 Improve database field default filling https://github.com/siyuan-note/siyuan/issues/11966
This commit is contained in:
parent
ca6088ac36
commit
8e182e803c
2 changed files with 7 additions and 17 deletions
|
@ -829,7 +829,7 @@ func calcRelativeTimeRegion(count int, unit RelativeDateUnit, direction Relative
|
|||
return
|
||||
}
|
||||
|
||||
func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value, addingBlockID string) (ret *Value) {
|
||||
func (filter *ViewFilter) GetAffectValue(key *Key, addingBlockID string) (ret *Value) {
|
||||
if nil != filter.Value {
|
||||
if KeyTypeRelation == filter.Value.Type || KeyTypeTemplate == filter.Value.Type || KeyTypeRollup == filter.Value.Type || KeyTypeUpdated == filter.Value.Type || KeyTypeCreated == filter.Value.Type {
|
||||
// 所有生成的数据都不设置默认值
|
||||
|
@ -860,16 +860,6 @@ func (filter *ViewFilter) GetAffectValue(key *Key, defaultVal *Value, addingBloc
|
|||
ret.CreatedAt = util.CurrentTimeMillis()
|
||||
ret.UpdatedAt = ret.CreatedAt + 1000
|
||||
|
||||
if nil != defaultVal {
|
||||
// 如果有默认值则优先使用默认值
|
||||
clonedDefaultVal := defaultVal.Clone()
|
||||
defaultRawVal := clonedDefaultVal.GetValByType(filter.Value.Type)
|
||||
if nil != defaultRawVal {
|
||||
ret.SetValByType(filter.Value.Type, defaultRawVal)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 没有默认值则使用过滤条件的值
|
||||
switch filter.Value.Type {
|
||||
case KeyTypeBlock:
|
||||
|
|
|
@ -85,12 +85,12 @@ func getAttrViewAddingBlockDefaultValues(attrView *av.AttributeView, view, group
|
|||
continue
|
||||
}
|
||||
|
||||
var defaultVal *av.Value
|
||||
var newValue *av.Value
|
||||
if nil != nearItem {
|
||||
defaultVal = nearItem.GetValue(filter.Column)
|
||||
newValue = getNewValueByNearItem(nearItem, keyValues.Key, addingBlockID)
|
||||
} else {
|
||||
newValue = filter.GetAffectValue(keyValues.Key, addingBlockID)
|
||||
}
|
||||
|
||||
newValue := filter.GetAffectValue(keyValues.Key, defaultVal, addingBlockID)
|
||||
if nil != newValue {
|
||||
ret[keyValues.Key.ID] = newValue
|
||||
}
|
||||
|
@ -4609,8 +4609,6 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
|
|||
}
|
||||
val.SetUpdatedAt(now)
|
||||
|
||||
regenAttrViewViewGroups(attrView, keyID)
|
||||
|
||||
if nil != key && av.KeyTypeRelation == key.Type && nil != key.Relation && key.Relation.IsTwoWay {
|
||||
// 双向关联需要同时更新目标字段的值
|
||||
|
||||
|
@ -4680,6 +4678,8 @@ func updateAttributeViewValue(tx *Transaction, attrView *av.AttributeView, keyID
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
regenAttrViewViewGroups(attrView, keyID)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue