This commit is contained in:
parent
622b6d2c84
commit
74ef94875b
2 changed files with 29 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue