🎨 Improve database created and updated column values https://github.com/siyuan-note/siyuan/issues/9391

This commit is contained in:
Daniel 2023-10-10 21:55:43 +08:00
parent f62be4719e
commit 301b6d9f70
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 92 additions and 11 deletions

View file

@ -169,6 +169,8 @@ func (value *Value) ToJSONString() string {
type ValueBlock struct {
ID string `json:"id"`
Content string `json:"content"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
}
type ValueText struct {
@ -510,6 +512,28 @@ func ParseAttributeView(avID string) (ret *AttributeView, err error) {
}
func SaveAttributeView(av *AttributeView) (err error) {
// 做一些数据兼容处理
now := util.CurrentTimeMillis()
for _, kv := range av.KeyValues {
if KeyTypeBlock == kv.Key.Type {
// 补全 block 的创建时间和更新时间
for _, v := range kv.Values {
if 0 == v.Block.Created {
createdStr := v.Block.ID[:len("20060102150405")]
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
if nil == parseErr {
v.Block.Created = created.UnixMilli()
} else {
v.Block.Created = now
}
}
if 0 == v.Block.Updated {
v.Block.Updated = now
}
}
}
}
data, err := gulu.JSON.MarshalIndentJSON(av, "", "\t") // TODO: single-line for production
if nil != err {
logging.LogErrorf("marshal attribute view [%s] failed: %s", av.ID, err)