Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: 重建历史索引遮罩 https://github.com/siyuan-note/siyuan/issues/7386

Liang Dingd5999b26d854
diff --git a/kernel/model/history.go b/kernel/model/history.go
index e9a9a14412..b89d0d8329 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -19,7 +19,6 @@ package model
import (
"encoding/json"
"fmt"
- "github.com/siyuan-note/eventbus"
"io/fs"
"math"
"os"
@@ -571,23 +570,20 @@ func ReindexHistory() (err error) {
return
}
- util.PushEndlessProgress(Conf.Language(35))
- defer util.PushClearProgress()
-
+ util.PushMsg(Conf.Language(35), 7*1000)
sql.InitHistoryDatabase(true)
lutEngine := util.NewLute()
- context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress}
for _, historyDir := range historyDirs {
if !historyDir.IsDir() {
continue
}
name := historyDir.Name()
- indexHistoryDirWithContext(name, lutEngine, context)
+ indexHistoryDir(name, lutEngine)
}
- sql.WaitForWritingHistoryDatabase()
+ util.ReloadUI()
return
}
@@ -600,10 +596,6 @@ const (
)
func indexHistoryDir(name string, luteEngine *lute.Lute) {
- indexHistoryDirWithContext(name, luteEngine, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar})
-}
-
-func indexHistoryDirWithContext(name string, luteEngine *lute.Lute, context map[string]interface{}) {
defer logging.Recover()
op := name[strings.LastIndex(name, "-")+1:]
@@ -667,7 +659,7 @@ func indexHistoryDirWithContext(name string, luteEngine *lute.Lute, context map[
})
}
- sql.IndexHistoriesQueue(histories, context)
+ sql.IndexHistoriesQueue(histories)
return
}
diff --git a/kernel/sql/database.go b/kernel/sql/database.go
index 610c13ebaf..0187e20cd3 100644
--- a/kernel/sql/database.go
+++ b/kernel/sql/database.go
@@ -214,7 +214,7 @@ func initHistoryDBConnection() {
historyDB.Close()
}
- dsn := util.HistoryDBPath + "?_journal_mode=OFF" +
+ dsn := util.DBPath + "?_journal_mode=WAL" +
"&_synchronous=OFF" +
"&_mmap_size=2684354560" +
"&_secure_delete=OFF" +
@@ -223,8 +223,7 @@ func initHistoryDBConnection() {
"&_busy_timeout=7000" +
"&_ignore_check_constraints=ON" +
"&_temp_store=MEMORY" +
- "&_case_sensitive_like=OFF" +
- "&_locking_mode=EXCLUSIVE"
+ "&_case_sensitive_like=OFF"
var err error
historyDB, err = sql.Open("sqlite3_extended", dsn)
if nil != err {
diff --git a/kernel/sql/queue_history.go b/kernel/sql/queue_history.go
index 64900dd7c4..e47ad78852 100644
--- a/kernel/sql/queue_history.go
+++ b/kernel/sql/queue_history.go
@@ -39,8 +39,7 @@ var (
type historyDBQueueOperation struct {
inQueueTime time.Time
- action string // index/deletePathPrefix
- context map[string]interface{} // 消息推送上下文
+ action string // index/deletePathPrefix
histories []*History // index
pathPrefix string // deletePathPrefix
@@ -71,9 +70,10 @@ func FlushHistoryQueue() {
return
}
- op.context["current"] = i
- op.context["total"] = total
- if err = execHistoryOp(op, tx); nil != err {
+ context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
+ context["current"] = i
+ context["total"] = total
+ if err = execHistoryOp(op, tx, context); nil != err {
tx.Rollback()
logging.LogErrorf("queue operation failed: %s", err)
continue
@@ -99,12 +99,12 @@ func FlushHistoryQueue() {
}
}
-func execHistoryOp(op *historyDBQueueOperation, tx *sql.Tx) (err error) {
+func execHistoryOp(op *historyDBQueueOperation, tx *sql.Tx, context map[string]interface{}) (err error) {
switch op.action {
case "index":
- err = insertHistories(tx, op.histories, op.context)
+ err = insertHistories(tx, op.histories, context)
case "deletePathPrefix":
- err = deleteHistoriesByPathPrefix(tx, op.pathPrefix, op.context)
+ err = deleteHistoriesByPathPrefix(tx, op.pathPrefix, context)
default:
msg := fmt.Sprintf("unknown history operation [%s]", op.action)
logging.LogErrorf(msg)
@@ -117,17 +117,15 @@ func DeleteHistoriesByPathPrefixQueue(pathPrefix string) {
historyDBQueueLock.Lock()
defer historyDBQueueLock.Unlock()
- newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "deletePathPrefix", pathPrefix: pathPrefix,
- context: map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}}
+ newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "deletePathPrefix", pathPrefix: pathPrefix}
historyOperationQueue = append(historyOperationQueue, newOp)
}
-func IndexHistoriesQueue(histories []*History, context map[string]interface{}) {
+func IndexHistoriesQueue(histories []*History) {
historyDBQueueLock.Lock()
defer historyDBQueueLock.Unlock()
- newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "index", histories: histories,
- context: context}
+ newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "index", histories: histories}
historyOperationQueue = append(historyOperationQueue, newOp)
}