mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-12 23:46:13 +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 = "{}"
|
editor.KaTexMacros = "{}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldVirtualBlockRef := model.Conf.Editor.VirtualBlockRef
|
||||||
|
oldVirtualBlockRefInclude := model.Conf.Editor.VirtualBlockRefInclude
|
||||||
|
oldVirtualBlockRefExclude := model.Conf.Editor.VirtualBlockRefExclude
|
||||||
|
|
||||||
model.Conf.Editor = editor
|
model.Conf.Editor = editor
|
||||||
model.Conf.Save()
|
model.Conf.Save()
|
||||||
|
|
||||||
|
|
@ -98,6 +102,12 @@ func setEditor(c *gin.Context) {
|
||||||
model.ChangeHistoryTick(editor.GenerateHistoryInterval)
|
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
|
ret.Data = model.Conf.Editor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,7 +242,7 @@ func setSearch(c *gin.Context) {
|
||||||
oldVirtualRefAnchor != s.VirtualRefAnchor ||
|
oldVirtualRefAnchor != s.VirtualRefAnchor ||
|
||||||
oldVirtualRefDoc != s.VirtualRefDoc ||
|
oldVirtualRefDoc != s.VirtualRefDoc ||
|
||||||
oldVirtualRefKeywordsLimit != s.VirtualRefKeywordsLimit {
|
oldVirtualRefKeywordsLimit != s.VirtualRefKeywordsLimit {
|
||||||
model.CacheVirtualBlockRefJob()
|
model.ResetVirtualBlockRefCache()
|
||||||
}
|
}
|
||||||
ret.Data = s
|
ret.Data = s
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
goahocorasick "github.com/anknown/ahocorasick"
|
|
||||||
"github.com/siyuan-note/logging"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -29,6 +27,7 @@ import (
|
||||||
"github.com/88250/lute"
|
"github.com/88250/lute"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
|
ahocorasick "github.com/BobuSumisu/aho-corasick"
|
||||||
"github.com/dgraph-io/ristretto"
|
"github.com/dgraph-io/ristretto"
|
||||||
"github.com/siyuan-note/siyuan/kernel/search"
|
"github.com/siyuan-note/siyuan/kernel/search"
|
||||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||||
|
|
@ -71,42 +70,22 @@ func putBlockVirtualRefKeywords(blockContent, blockID, docTitle string) (ret []s
|
||||||
}
|
}
|
||||||
|
|
||||||
contentTmp := blockContent
|
contentTmp := blockContent
|
||||||
var keywordsTmp [][]rune
|
var keywordsTmp []string
|
||||||
if !Conf.Search.CaseSensitive {
|
if !Conf.Search.CaseSensitive {
|
||||||
contentTmp = strings.ToLower(blockContent)
|
contentTmp = strings.ToLower(blockContent)
|
||||||
for _, keyword := range keywords {
|
for _, keyword := range keywords {
|
||||||
keywordsTmp = append(keywordsTmp, []rune(strings.ToLower(keyword)))
|
keywordsTmp = append(keywordsTmp, strings.ToLower(keyword))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, keyword := range keywords {
|
for _, keyword := range keywords {
|
||||||
keywordsTmp = append(keywordsTmp, []rune(keyword))
|
keywordsTmp = append(keywordsTmp, keyword)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if 1024*1024 < len(contentTmp) {
|
trie := ahocorasick.NewTrieBuilder().AddStrings(keywordsTmp).Build()
|
||||||
m := goahocorasick.Machine{}
|
hits := trie.MatchString(contentTmp)
|
||||||
buildErr := m.Build(keywordsTmp)
|
for _, hit := range hits {
|
||||||
if nil != buildErr {
|
ret = append(ret, hit.MatchString())
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if 1 > len(ret) {
|
if 1 > len(ret) {
|
||||||
|
|
@ -128,6 +107,11 @@ func CacheVirtualBlockRefJob() {
|
||||||
virtualBlockRefCache.Set("virtual_ref", keywords, 1)
|
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 {
|
func processVirtualRef(n *ast.Node, unlinks *[]*ast.Node, virtualBlockRefKeywords []string, refCount map[string]int, luteEngine *lute.Lute) bool {
|
||||||
if !Conf.Editor.VirtualBlockRef {
|
if !Conf.Editor.VirtualBlockRef {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -274,8 +274,8 @@ func queryDocIDsByTitle(title string, excludeIDs []string) (ret []string) {
|
||||||
|
|
||||||
func queryDocTitles() (ret []string) {
|
func queryDocTitles() (ret []string) {
|
||||||
ret = []string{}
|
ret = []string{}
|
||||||
sqlStmt := "SELECT content FROM blocks WHERE type = 'd' LIMIT ?"
|
sqlStmt := "SELECT content FROM blocks WHERE type = 'd'"
|
||||||
rows, err := query(sqlStmt, 10240)
|
rows, err := query(sqlStmt)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue