mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 08:00:13 +01:00
⚡ 改进反链面板加载性能 Fix https://github.com/siyuan-note/siyuan/issues/6724
This commit is contained in:
parent
fb14f7a46a
commit
2ce8ce79bd
1 changed files with 24 additions and 3 deletions
|
|
@ -598,11 +598,29 @@ func GetAllRootBlocks() (ret []*Block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBlocks(ids []string) (ret []*Block) {
|
func GetBlocks(ids []string) (ret []*Block) {
|
||||||
length := len(ids)
|
var notHitIDs []string
|
||||||
|
cached := map[string]*Block{}
|
||||||
|
for _, id := range ids {
|
||||||
|
b := getBlockCache(id)
|
||||||
|
if nil != b {
|
||||||
|
cached[id] = b
|
||||||
|
} else {
|
||||||
|
notHitIDs = append(notHitIDs, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if 1 > len(notHitIDs) {
|
||||||
|
for _, id := range ids {
|
||||||
|
ret = append(ret, cached[id])
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
length := len(notHitIDs)
|
||||||
stmtBuilder := bytes.Buffer{}
|
stmtBuilder := bytes.Buffer{}
|
||||||
stmtBuilder.WriteString("SELECT * FROM blocks WHERE id IN (")
|
stmtBuilder.WriteString("SELECT * FROM blocks WHERE id IN (")
|
||||||
var args []interface{}
|
var args []interface{}
|
||||||
for i, id := range ids {
|
for i, id := range notHitIDs {
|
||||||
args = append(args, id)
|
args = append(args, id)
|
||||||
stmtBuilder.WriteByte('?')
|
stmtBuilder.WriteByte('?')
|
||||||
if i < length-1 {
|
if i < length-1 {
|
||||||
|
|
@ -619,10 +637,13 @@ func GetBlocks(ids []string) (ret []*Block) {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
if block := scanBlockRows(rows); nil != block {
|
if block := scanBlockRows(rows); nil != block {
|
||||||
ret = append(ret, block)
|
|
||||||
putBlockCache(block)
|
putBlockCache(block)
|
||||||
|
cached[block.ID] = block
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, id := range ids {
|
||||||
|
ret = append(ret, cached[id])
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue