mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-01 13:11:48 +01:00
🎨 调整虚拟引用搜索设置项后立即重置缓存 https://github.com/siyuan-note/siyuan/issues/7378
This commit is contained in:
parent
4485cc1f1d
commit
5f72a7b2cd
3 changed files with 26 additions and 32 deletions
|
|
@ -91,6 +91,10 @@ func setEditor(c *gin.Context) {
|
|||
editor.KaTexMacros = "{}"
|
||||
}
|
||||
|
||||
oldVirtualBlockRef := model.Conf.Editor.VirtualBlockRef
|
||||
oldVirtualBlockRefInclude := model.Conf.Editor.VirtualBlockRefInclude
|
||||
oldVirtualBlockRefExclude := model.Conf.Editor.VirtualBlockRefExclude
|
||||
|
||||
model.Conf.Editor = editor
|
||||
model.Conf.Save()
|
||||
|
||||
|
|
@ -98,6 +102,12 @@ func setEditor(c *gin.Context) {
|
|||
model.ChangeHistoryTick(editor.GenerateHistoryInterval)
|
||||
}
|
||||
|
||||
if oldVirtualBlockRef != model.Conf.Editor.VirtualBlockRef ||
|
||||
oldVirtualBlockRefInclude != model.Conf.Editor.VirtualBlockRefInclude ||
|
||||
oldVirtualBlockRefExclude != model.Conf.Editor.VirtualBlockRefExclude {
|
||||
model.ResetVirtualBlockRefCache()
|
||||
}
|
||||
|
||||
ret.Data = model.Conf.Editor
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +242,7 @@ func setSearch(c *gin.Context) {
|
|||
oldVirtualRefAnchor != s.VirtualRefAnchor ||
|
||||
oldVirtualRefDoc != s.VirtualRefDoc ||
|
||||
oldVirtualRefKeywordsLimit != s.VirtualRefKeywordsLimit {
|
||||
model.CacheVirtualBlockRefJob()
|
||||
model.ResetVirtualBlockRefCache()
|
||||
}
|
||||
ret.Data = s
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ package model
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
goahocorasick "github.com/anknown/ahocorasick"
|
||||
"github.com/siyuan-note/logging"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
|
@ -29,6 +27,7 @@ import (
|
|||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
ahocorasick "github.com/BobuSumisu/aho-corasick"
|
||||
"github.com/dgraph-io/ristretto"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
|
@ -71,42 +70,22 @@ func putBlockVirtualRefKeywords(blockContent, blockID, docTitle string) (ret []s
|
|||
}
|
||||
|
||||
contentTmp := blockContent
|
||||
var keywordsTmp [][]rune
|
||||
var keywordsTmp []string
|
||||
if !Conf.Search.CaseSensitive {
|
||||
contentTmp = strings.ToLower(blockContent)
|
||||
for _, keyword := range keywords {
|
||||
keywordsTmp = append(keywordsTmp, []rune(strings.ToLower(keyword)))
|
||||
keywordsTmp = append(keywordsTmp, strings.ToLower(keyword))
|
||||
}
|
||||
} else {
|
||||
for _, keyword := range keywords {
|
||||
keywordsTmp = append(keywordsTmp, []rune(keyword))
|
||||
keywordsTmp = append(keywordsTmp, keyword)
|
||||
}
|
||||
}
|
||||
|
||||
if 1024*1024 < len(contentTmp) {
|
||||
m := goahocorasick.Machine{}
|
||||
buildErr := m.Build(keywordsTmp)
|
||||
if nil != buildErr {
|
||||
logging.LogWarnf("build virtual ref keywords AC matcher failed: %s", buildErr)
|
||||
for _, keywordRunes := range keywordsTmp {
|
||||
keyword := string(keywordRunes)
|
||||
if strings.Contains(contentTmp, keyword) {
|
||||
ret = append(ret, keyword)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hits := m.MultiPatternSearch([]rune(contentTmp), false)
|
||||
for _, hit := range hits {
|
||||
ret = append(ret, string(hit.Word))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, keywordRunes := range keywordsTmp {
|
||||
keyword := string(keywordRunes)
|
||||
if strings.Contains(contentTmp, keyword) {
|
||||
ret = append(ret, keyword)
|
||||
}
|
||||
}
|
||||
trie := ahocorasick.NewTrieBuilder().AddStrings(keywordsTmp).Build()
|
||||
hits := trie.MatchString(contentTmp)
|
||||
for _, hit := range hits {
|
||||
ret = append(ret, hit.MatchString())
|
||||
}
|
||||
|
||||
if 1 > len(ret) {
|
||||
|
|
@ -128,6 +107,11 @@ func CacheVirtualBlockRefJob() {
|
|||
virtualBlockRefCache.Set("virtual_ref", keywords, 1)
|
||||
}
|
||||
|
||||
func ResetVirtualBlockRefCache() {
|
||||
virtualBlockRefCache.Clear()
|
||||
CacheVirtualBlockRefJob()
|
||||
}
|
||||
|
||||
func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeywords []string, refCount map[string]int, luteEngine *lute.Lute) bool {
|
||||
if !Conf.Editor.VirtualBlockRef {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -274,8 +274,8 @@ func queryDocIDsByTitle(title string, excludeIDs []string) (ret []string) {
|
|||
|
||||
func queryDocTitles() (ret []string) {
|
||||
ret = []string{}
|
||||
sqlStmt := "SELECT content FROM blocks WHERE type = 'd' LIMIT ?"
|
||||
rows, err := query(sqlStmt, 10240)
|
||||
sqlStmt := "SELECT content FROM blocks WHERE type = 'd'"
|
||||
rows, err := query(sqlStmt)
|
||||
if nil != err {
|
||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue