Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:zap: 改进反链面板加载性能 Fix https://github.com/siyuan-note/siyuan/issues/6724

Liang Ding2ce8ce79bd7a
diff --git a/kernel/sql/block_query.go b/kernel/sql/block_query.go
index 7f3356e28a..a1a4b12146 100644
--- a/kernel/sql/block_query.go
+++ b/kernel/sql/block_query.go
@@ -598,11 +598,29 @@ func GetAllRootBlocks() (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.WriteString("SELECT * FROM blocks WHERE id IN (")
var args []interface{}
- for i, id := range ids {
+ for i, id := range notHitIDs {
args = append(args, id)
stmtBuilder.WriteByte('?')
if i < length-1 {
@@ -619,10 +637,13 @@ func GetBlocks(ids []string) (ret []*Block) {
defer rows.Close()
for rows.Next() {
if block := scanBlockRows(rows); nil != block {
- ret = append(ret, block)
putBlockCache(block)
+ cached[block.ID] = block
}
}
+ for _, id := range ids {
+ ret = append(ret, cached[id])
+ }
return
}