This commit is contained in:
Liang Ding 2023-02-17 22:29:12 +08:00
parent fa1ee8f4a1
commit d5999b26d8
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 17 additions and 28 deletions

View file

@ -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
}

View file

@ -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 {

View file

@ -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)
}