This commit is contained in:
Liang Ding 2023-01-19 15:27:50 +08:00
parent 622b6d2c84
commit 74ef94875b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 29 additions and 7 deletions

View file

@ -38,6 +38,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
"github.com/xrash/smetrics"
@ -69,6 +70,9 @@ func searchEmbedBlock(embedBlockID, stmt string, excludeIDs []string, headingMod
}
sqlBlocks = tmp
// 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
task.AppendTask(task.DatabaseIndexEmbedBlock, updateEmbedBlockContent, embedBlockID, sqlBlocks)
// 缓存最多 128 棵语法树
trees := map[string]*parse.Tree{}
count := 0

View file

@ -1219,21 +1219,24 @@ func updateRefText(refNode *ast.Node, changedDefNodes map[string]*ast.Node) (cha
// AutoIndexEmbedBlock 嵌入块支持搜索 https://github.com/siyuan-note/siyuan/issues/7112
func AutoIndexEmbedBlock() {
for {
task.AppendTask(task.DatabaseIndexEmbedBlock, autoIndexEmbedBlock)
embedBlocks := sql.QueryEmptyContentEmbedBlocks()
task.AppendTask(task.DatabaseIndexEmbedBlock, autoIndexEmbedBlock, embedBlocks)
time.Sleep(10 * time.Minute)
}
}
func autoIndexEmbedBlock() {
embedBlocks := sql.QueryEmptyContentEmbedBlocks()
func autoIndexEmbedBlock(embedBlocks []*sql.Block) {
for i, embedBlock := range embedBlocks {
stmt := strings.TrimPrefix(embedBlock.Markdown, "{{")
stmt = strings.TrimSuffix(stmt, "}}")
blocks := sql.SelectBlocksRawStmtNoParse(stmt, 102400)
for _, block := range blocks {
embedBlock.Content = block.Content
sql.UpdateBlockContent(embedBlock)
queryResultBlocks := sql.SelectBlocksRawStmtNoParse(stmt, 102400)
for _, block := range queryResultBlocks {
embedBlock.Content += block.Content
}
if "" == embedBlock.Content {
embedBlock.Content = "no query result"
}
sql.UpdateBlockContent(embedBlock)
if 63 <= i { // 一次任务中最多处理 64 个嵌入块,防止卡顿
break
@ -1241,6 +1244,21 @@ func autoIndexEmbedBlock() {
}
}
func updateEmbedBlockContent(embedBlockID string, queryResultBlocks []*sql.Block) {
embedBlock := sql.GetBlock(embedBlockID)
if nil == embedBlock {
return
}
for _, block := range queryResultBlocks {
embedBlock.Content += block.Content
}
if "" == embedBlock.Content {
embedBlock.Content = "no query result"
}
sql.UpdateBlockContent(embedBlock)
}
// AutoFixIndex 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
func AutoFixIndex() {
for {