🐛 Primary key value unexpectedly updated when database adds row https://github.com/siyuan-note/siyuan/issues/11018
This commit is contained in:
parent
20fb74c8d7
commit
bc8b295733
2 changed files with 7 additions and 7 deletions
|
@ -340,6 +340,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
|||
// 补全 block 的创建时间和更新时间
|
||||
for _, v := range kv.Values {
|
||||
if 0 == v.Block.Created {
|
||||
logging.LogWarnf("block [%s] created time is empty", v.BlockID)
|
||||
if "" == v.Block.ID {
|
||||
v.Block.ID = v.BlockID
|
||||
if "" == v.Block.ID {
|
||||
|
@ -357,6 +358,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
|||
}
|
||||
}
|
||||
if 0 == v.Block.Updated {
|
||||
logging.LogWarnf("block [%s] updated time is empty", v.BlockID)
|
||||
v.Block.Updated = v.Block.Created
|
||||
}
|
||||
}
|
||||
|
@ -375,6 +377,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
|||
val.KeyID = kv.Key.ID
|
||||
}
|
||||
if "" == v.KeyID {
|
||||
logging.LogWarnf("value [%s] key id is empty", v.ID)
|
||||
v.KeyID = kv.Key.ID
|
||||
}
|
||||
|
||||
|
@ -417,10 +420,12 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
|||
|
||||
// 补全值的创建时间和更新时间
|
||||
if "" == v.ID {
|
||||
logging.LogWarnf("value id is empty")
|
||||
v.ID = ast.NewNodeID()
|
||||
}
|
||||
|
||||
if 0 == v.CreatedAt {
|
||||
logging.LogWarnf("value [%s] created time is empty", v.ID)
|
||||
createdStr := v.ID[:len("20060102150405")]
|
||||
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
|
||||
if nil == parseErr {
|
||||
|
@ -431,6 +436,7 @@ func SaveAttributeView(av *AttributeView) (err error) {
|
|||
}
|
||||
|
||||
if 0 == v.UpdatedAt {
|
||||
logging.LogWarnf("value [%s] updated time is empty", v.ID)
|
||||
v.UpdatedAt = v.CreatedAt
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2971,7 +2971,7 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
|
|||
}
|
||||
|
||||
for _, value := range keyValues.Values {
|
||||
if cellID == value.ID {
|
||||
if cellID == value.ID || rowID == value.BlockID {
|
||||
val = value
|
||||
val.Type = keyValues.Key.Type
|
||||
break
|
||||
|
@ -3003,12 +3003,6 @@ func UpdateAttributeViewCell(tx *Transaction, avID, keyID, rowID, cellID string,
|
|||
return
|
||||
}
|
||||
|
||||
if "" == val.ID {
|
||||
// 有时前端会误调用该接口(比如创建完快速切换),这里判断一下,避免误更新刚刚创建的值
|
||||
// Primary key value unexpectedly updated when database adds row https://github.com/siyuan-note/siyuan/issues/11018
|
||||
return
|
||||
}
|
||||
|
||||
if av.KeyTypeNumber == val.Type {
|
||||
if nil != val.Number && !val.Number.IsNotEmpty {
|
||||
val.Number.Content = 0
|
||||
|
|
Loading…
Add table
Reference in a new issue