mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-24 09:16:09 +01:00
🎨 Improve database created and updated column values https://github.com/siyuan-note/siyuan/issues/9391
This commit is contained in:
parent
f62be4719e
commit
301b6d9f70
2 changed files with 92 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue