mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
♻️ Improve database loading performance https://github.com/siyuan-note/siyuan/issues/12818
This commit is contained in:
parent
d675496e52
commit
9cea8ca069
2 changed files with 41 additions and 24 deletions
|
|
@ -176,6 +176,16 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
ret.Rows = append(ret.Rows, &tableRow)
|
||||
}
|
||||
|
||||
// 批量获取块属性以提升性能
|
||||
var ialIDs []string
|
||||
for _, row := range ret.Rows {
|
||||
block := row.GetBlockValue()
|
||||
if nil != block && !block.IsDetached {
|
||||
ialIDs = append(ialIDs, row.ID)
|
||||
}
|
||||
}
|
||||
ials := BatchGetBlockAttrs(ialIDs)
|
||||
|
||||
// 渲染自动生成的列值,比如关联列、汇总列、创建时间列和更新时间列
|
||||
for _, row := range ret.Rows {
|
||||
for _, cell := range row.Cells {
|
||||
|
|
@ -266,11 +276,11 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
keyValues = append(keyValues, &av.KeyValues{Key: createdKey, Values: []*av.Value{{ID: cell.Value.ID, KeyID: createdKey.ID, BlockID: row.ID, Type: av.KeyTypeCreated, Created: cell.Value.Created}}})
|
||||
rows[row.ID] = keyValues
|
||||
case av.KeyTypeUpdated: // 渲染更新时间
|
||||
ial := map[string]string{}
|
||||
block := row.GetBlockValue()
|
||||
if nil != block && !block.IsDetached {
|
||||
ial = GetBlockAttrs(row.ID)
|
||||
ial := ials[row.ID]
|
||||
if nil == ial {
|
||||
ial = map[string]string{}
|
||||
}
|
||||
block := row.GetBlockValue()
|
||||
updatedStr := ial["updated"]
|
||||
if "" == updatedStr && nil != block {
|
||||
cell.Value.Updated = av.NewFormattedValueUpdated(block.Block.Updated, 0, av.UpdatedFormatNone)
|
||||
|
|
@ -302,10 +312,9 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
|
|||
switch cell.ValueType {
|
||||
case av.KeyTypeTemplate: // 渲染模板列
|
||||
keyValues := rows[row.ID]
|
||||
ial := map[string]string{}
|
||||
block := row.GetBlockValue()
|
||||
if nil != block && !block.IsDetached {
|
||||
ial = GetBlockAttrs(row.ID)
|
||||
ial := ials[row.ID]
|
||||
if nil == ial {
|
||||
ial = map[string]string{}
|
||||
}
|
||||
content, renderErr := RenderTemplateCol(ial, keyValues, cell.Value.Template.Content)
|
||||
cell.Value.Template.Content = content
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue