Browse Source

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

Liang Ding 2 năm trước cách đây
mục cha
commit
fa1ee8f4a1
3 tập tin đã thay đổi với 24 bổ sung15 xóa
  1. 1 1
      app/appearance/langs/zh_CHT.json
  2. 9 2
      kernel/model/history.go
  3. 14 12
      kernel/sql/queue_history.go

+ 1 - 1
app/appearance/langs/zh_CHT.json

@@ -1091,6 +1091,6 @@
     "188": "鎖定雲端同步目錄失敗,請稍後再試",
     "189": "雲端同步目錄還在被其他設備鎖定,請稍後再試",
     "190": "校驗索引時發現一個問題,已經自動修復",
-    "191": "[%d/%d] 已经建立条历史数据索引"
+    "191": "[%d/%d] 已經建立條歷史數據索引"
   }
 }

+ 9 - 2
kernel/model/history.go

@@ -19,6 +19,7 @@ package model
 import (
 	"encoding/json"
 	"fmt"
+	"github.com/siyuan-note/eventbus"
 	"io/fs"
 	"math"
 	"os"
@@ -575,13 +576,15 @@ func ReindexHistory() (err error) {
 
 	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()
-		indexHistoryDir(name, lutEngine)
+		indexHistoryDirWithContext(name, lutEngine, context)
 	}
 
 	sql.WaitForWritingHistoryDatabase()
@@ -597,6 +600,10 @@ 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:]
@@ -660,7 +667,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
 		})
 	}
 
-	sql.IndexHistoriesQueue(histories)
+	sql.IndexHistoriesQueue(histories, context)
 	return
 }
 

+ 14 - 12
kernel/sql/queue_history.go

@@ -20,11 +20,11 @@ import (
 	"database/sql"
 	"errors"
 	"fmt"
+	"github.com/siyuan-note/eventbus"
 	"runtime/debug"
 	"sync"
 	"time"
 
-	"github.com/siyuan-note/eventbus"
 	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/siyuan/kernel/task"
 	"github.com/siyuan-note/siyuan/kernel/util"
@@ -39,7 +39,8 @@ var (
 
 type historyDBQueueOperation struct {
 	inQueueTime time.Time
-	action      string // index/deletePathPrefix
+	action      string                 // index/deletePathPrefix
+	context     map[string]interface{} // 消息推送上下文
 
 	histories  []*History // index
 	pathPrefix string     // deletePathPrefix
@@ -59,7 +60,6 @@ func FlushHistoryQueue() {
 	defer txLock.Unlock()
 	start := time.Now()
 
-	context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress}
 	total := len(ops)
 	for i, op := range ops {
 		if util.IsExiting {
@@ -71,9 +71,9 @@ func FlushHistoryQueue() {
 			return
 		}
 
-		context["current"] = i
-		context["total"] = total
-		if err = execHistoryOp(op, tx, context); nil != err {
+		op.context["current"] = i
+		op.context["total"] = total
+		if err = execHistoryOp(op, tx); 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, context map[string]interface{}) (err error) {
+func execHistoryOp(op *historyDBQueueOperation, tx *sql.Tx) (err error) {
 	switch op.action {
 	case "index":
-		err = insertHistories(tx, op.histories, context)
+		err = insertHistories(tx, op.histories, op.context)
 	case "deletePathPrefix":
-		err = deleteHistoriesByPathPrefix(tx, op.pathPrefix, context)
+		err = deleteHistoriesByPathPrefix(tx, op.pathPrefix, op.context)
 	default:
 		msg := fmt.Sprintf("unknown history operation [%s]", op.action)
 		logging.LogErrorf(msg)
@@ -117,15 +117,17 @@ func DeleteHistoriesByPathPrefixQueue(pathPrefix string) {
 	historyDBQueueLock.Lock()
 	defer historyDBQueueLock.Unlock()
 
-	newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "deletePathPrefix", pathPrefix: pathPrefix}
+	newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "deletePathPrefix", pathPrefix: pathPrefix,
+		context: map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}}
 	historyOperationQueue = append(historyOperationQueue, newOp)
 }
 
-func IndexHistoriesQueue(histories []*History) {
+func IndexHistoriesQueue(histories []*History, context map[string]interface{}) {
 	historyDBQueueLock.Lock()
 	defer historyDBQueueLock.Unlock()
 
-	newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "index", histories: histories}
+	newOp := &historyDBQueueOperation{inQueueTime: time.Now(), action: "index", histories: histories,
+		context: context}
 	historyOperationQueue = append(historyOperationQueue, newOp)
 }