🎨 Auto rebuild history database index when indexing failed https://github.com/siyuan-note/siyuan/issues/8543

This commit is contained in:
Daniel 2023-06-15 10:22:28 +08:00
parent 47df8b6018
commit f7d8a02138
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 14 additions and 1 deletions

View file

@ -33,6 +33,7 @@ import (
"github.com/88250/lute/ast" "github.com/88250/lute/ast"
"github.com/88250/lute/parse" "github.com/88250/lute/parse"
"github.com/88250/lute/render" "github.com/88250/lute/render"
"github.com/siyuan-note/eventbus"
"github.com/siyuan-note/filelock" "github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/conf" "github.com/siyuan-note/siyuan/kernel/conf"
@ -691,3 +692,13 @@ func fromSQLHistories(sqlHistories []*sql.History) (ret []*HistoryItem) {
} }
return return
} }
func init() {
subscribeSQLHistoryEvents()
}
func subscribeSQLHistoryEvents() {
eventbus.Subscribe(util.EvtSQLHistoryRebuild, func() {
ReindexHistory()
})
}

View file

@ -83,7 +83,7 @@ func FlushHistoryQueue() {
if err = execHistoryOp(op, tx, context); nil != err { 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)
util.PushMsg("History database index failed, please try to manually rebuild it in [Data history - File history]", 5000) eventbus.Publish(util.EvtSQLHistoryRebuild)
return return
} }

View file

@ -404,4 +404,6 @@ func existAvailabilityStatus(workspaceAbsPath string) bool {
const ( const (
EvtConfPandocInitialized = "conf.pandoc.initialized" EvtConfPandocInitialized = "conf.pandoc.initialized"
EvtSQLHistoryRebuild = "sql.history.rebuild"
) )