Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2022-11-18 16:03:53 +08:00
commit b09ca6f55b
2 changed files with 10 additions and 11 deletions

View file

@ -85,7 +85,7 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str
}
re := ic + "("
for i, k := range keywords {
k = keyword2regexp(k)
k = regexp.QuoteMeta(k)
re += "(" + k + ")"
if i < len(keywords)-1 {
re += "|"
@ -98,7 +98,7 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str
})
} else {
for _, k := range keywords {
k = keyword2regexp(k)
k = regexp.QuoteMeta(k)
var repls, words []string
if re, err := regexp.Compile(ic + k); nil == err {
words = re.FindAllString(text, -1)
@ -115,12 +115,3 @@ func EncloseHighlighting(text string, keywords []string, openMark, closeMark str
}
return text
}
func keyword2regexp(k string) string {
k = strings.ReplaceAll(k, "*", ".*")
k = strings.ReplaceAll(k, "?", ".")
k = strings.ReplaceAll(k, "%", ".*")
k = strings.ReplaceAll(k, "_", ".")
k = strings.ReplaceAll(k, "\\\\", "\\")
return k
}

View file

@ -70,11 +70,19 @@ func removeBlockCache(id string) {
removeRefCacheByDefID(id)
}
var virtualRefKeywordsCacheTime = time.Now()
func getVirtualRefKeywordsCache() ([]string, bool) {
if disabled {
return nil, false
}
// 虚拟引用关键字缓存调整为 10 分钟 https://github.com/siyuan-note/siyuan/issues/6602
if 10 < time.Now().Sub(virtualRefKeywordsCacheTime).Minutes() {
ClearVirtualRefKeywords()
return nil, false
}
if val, ok := memCache.Get("virtual_ref"); ok {
return val.([]string), true
}