mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
This commit is contained in:
parent
fa1ee8f4a1
commit
d5999b26d8
3 changed files with 17 additions and 28 deletions
|
|
@ -19,7 +19,6 @@ package model
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/siyuan-note/eventbus"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -571,23 +570,20 @@ func ReindexHistory() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
util.PushEndlessProgress(Conf.Language(35))
|
util.PushMsg(Conf.Language(35), 7*1000)
|
||||||
defer util.PushClearProgress()
|
|
||||||
|
|
||||||
sql.InitHistoryDatabase(true)
|
sql.InitHistoryDatabase(true)
|
||||||
lutEngine := util.NewLute()
|
lutEngine := util.NewLute()
|
||||||
|
|
||||||
context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress}
|
|
||||||
for _, historyDir := range historyDirs {
|
for _, historyDir := range historyDirs {
|
||||||
if !historyDir.IsDir() {
|
if !historyDir.IsDir() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
name := historyDir.Name()
|
name := historyDir.Name()
|
||||||
indexHistoryDirWithContext(name, lutEngine, context)
|
indexHistoryDir(name, lutEngine)
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.WaitForWritingHistoryDatabase()
|
util.ReloadUI()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -600,10 +596,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
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()
|
defer logging.Recover()
|
||||||
|
|
||||||
op := name[strings.LastIndex(name, "-")+1:]
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ func initHistoryDBConnection() {
|
||||||
historyDB.Close()
|
historyDB.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
dsn := util.HistoryDBPath + "?_journal_mode=OFF" +
|
dsn := util.DBPath + "?_journal_mode=WAL" +
|
||||||
"&_synchronous=OFF" +
|
"&_synchronous=OFF" +
|
||||||
"&_mmap_size=2684354560" +
|
"&_mmap_size=2684354560" +
|
||||||
"&_secure_delete=OFF" +
|
"&_secure_delete=OFF" +
|
||||||
|
|
@ -223,8 +223,7 @@ func initHistoryDBConnection() {
|
||||||
"&_busy_timeout=7000" +
|
"&_busy_timeout=7000" +
|
||||||
"&_ignore_check_constraints=ON" +
|
"&_ignore_check_constraints=ON" +
|
||||||
"&_temp_store=MEMORY" +
|
"&_temp_store=MEMORY" +
|
||||||
"&_case_sensitive_like=OFF" +
|
"&_case_sensitive_like=OFF"
|
||||||
"&_locking_mode=EXCLUSIVE"
|
|
||||||
var err error
|
var err error
|
||||||
historyDB, err = sql.Open("sqlite3_extended", dsn)
|
historyDB, err = sql.Open("sqlite3_extended", dsn)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ var (
|
||||||
type historyDBQueueOperation struct {
|
type historyDBQueueOperation struct {
|
||||||
inQueueTime time.Time
|
inQueueTime time.Time
|
||||||
action string // index/deletePathPrefix
|
action string // index/deletePathPrefix
|
||||||
context map[string]interface{} // 消息推送上下文
|
|
||||||
|
|
||||||
histories []*History // index
|
histories []*History // index
|
||||||
pathPrefix string // deletePathPrefix
|
pathPrefix string // deletePathPrefix
|
||||||
|
|
@ -71,9 +70,10 @@ func FlushHistoryQueue() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
op.context["current"] = i
|
context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||||
op.context["total"] = total
|
context["current"] = i
|
||||||
if err = execHistoryOp(op, tx); nil != err {
|
context["total"] = total
|
||||||
|
if err = execHistoryOp(op, tx, context); nil != err {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
logging.LogErrorf("queue operation failed: %s", err)
|
logging.LogErrorf("queue operation failed: %s", err)
|
||||||
continue
|
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 {
|
switch op.action {
|
||||||
case "index":
|
case "index":
|
||||||
err = insertHistories(tx, op.histories, op.context)
|
err = insertHistories(tx, op.histories, context)
|
||||||
case "deletePathPrefix":
|
case "deletePathPrefix":
|
||||||
err = deleteHistoriesByPathPrefix(tx, op.pathPrefix, op.context)
|
err = deleteHistoriesByPathPrefix(tx, op.pathPrefix, context)
|
||||||
default:
|
default:
|
||||||
msg := fmt.Sprintf("unknown history operation [%s]", op.action)
|
msg := fmt.Sprintf("unknown history operation [%s]", op.action)
|
||||||
logging.LogErrorf(msg)
|
logging.LogErrorf(msg)
|
||||||
|
|
@ -117,17 +117,15 @@ func DeleteHistoriesByPathPrefixQueue(pathPrefix string) {
|
||||||
historyDBQueueLock.Lock()
|
historyDBQueueLock.Lock()
|
||||||
defer historyDBQueueLock.Unlock()
|
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)
|
historyOperationQueue = append(historyOperationQueue, newOp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IndexHistoriesQueue(histories []*History, context map[string]interface{}) {
|
func IndexHistoriesQueue(histories []*History) {
|
||||||
historyDBQueueLock.Lock()
|
historyDBQueueLock.Lock()
|
||||||
defer historyDBQueueLock.Unlock()
|
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)
|
historyOperationQueue = append(historyOperationQueue, newOp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue