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/6655

Liang Dingb6e6c35f9ff1
diff --git a/kernel/sql/block_query.go b/kernel/sql/block_query.go
index 8581bfe32a..7f3356e28a 100644
--- a/kernel/sql/block_query.go
+++ b/kernel/sql/block_query.go
@@ -502,6 +502,7 @@ func scanBlockRow(row *sql.Row) (ret *Block) {
return
}
ret = &block
+ putBlockCache(ret)
return
}
diff --git a/kernel/sql/cache.go b/kernel/sql/cache.go
index ff12788131..c0cc49e8f7 100644
--- a/kernel/sql/cache.go
+++ b/kernel/sql/cache.go
@@ -23,7 +23,9 @@ import (
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/dgraph-io/ristretto"
+ "github.com/jinzhu/copier"
gcache "github.com/patrickmn/go-cache"
+ "github.com/siyuan-note/logging"
)
var memCache, _ = ristretto.NewCache(&ristretto.Config{
@@ -50,7 +52,13 @@ func putBlockCache(block *Block) {
if disabled {
return
}
- memCache.Set(block.ID, block, 1)
+
+ cloned := &Block{}
+ if err := copier.Copy(cloned, block); nil != err {
+ logging.LogErrorf("clone block failed: %v", err)
+ return
+ }
+ memCache.Set(cloned.ID, cloned, 1)
}
func getBlockCache(id string) (ret *Block) {