From b6e6c35f9ff18ce098123a1b8c0fea947d34397e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 21 Nov 2022 10:20:11 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E6=94=B9=E8=BF=9B=E5=9D=97=E5=BC=95?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=80=A7=E8=83=BD=20Fix=20https://github.com?= =?UTF-8?q?/siyuan-note/siyuan/issues/6655?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/sql/block_query.go | 1 + kernel/sql/cache.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/sql/block_query.go b/kernel/sql/block_query.go index 8581bfe32..7f3356e28 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 ff1278813..c0cc49e8f 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) {