This commit is contained in:
Liang Ding 2022-11-21 10:20:11 +08:00
parent 4650eec7c6
commit b6e6c35f9f
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 10 additions and 1 deletions

View file

@ -502,6 +502,7 @@ func scanBlockRow(row *sql.Row) (ret *Block) {
return
}
ret = &block
putBlockCache(ret)
return
}

View file

@ -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) {