mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-13 16:06:13 +01:00
🎨 Improve reindex
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
ecfb9329f9
commit
f7f05ffad1
3 changed files with 51 additions and 52 deletions
|
|
@ -102,12 +102,7 @@ func InitDatabase(forceRebuild bool) (err error) {
|
|||
// 不存在库或者版本不一致都会走到这里
|
||||
|
||||
closeDatabase()
|
||||
if gulu.File.IsExist(util.DBPath) {
|
||||
if err = removeDatabaseFile(); err != nil {
|
||||
logging.LogErrorf("remove database file failed: %s", err)
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
util.RemoveDatabaseFile(util.DBPath)
|
||||
|
||||
initDBConnection()
|
||||
initDBTables()
|
||||
|
|
@ -1486,13 +1481,14 @@ func prepareExecInsertTx(tx *sql.Tx, stmtSQL string, args []interface{}) (err er
|
|||
}
|
||||
|
||||
if _, err = stmt.Exec(args...); err != nil {
|
||||
tx.Rollback()
|
||||
logging.LogErrorf("exec database stmt [%s] failed: %s\n %s", stmtSQL, err, logging.ShortStack())
|
||||
|
||||
if strings.Contains(err.Error(), "database disk image is malformed") {
|
||||
tx.Rollback()
|
||||
closeDatabase()
|
||||
removeDatabaseFile()
|
||||
util.RemoveDatabaseFile(util.DBPath)
|
||||
logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it\n\t%s\n\t%v", util.DBPath, stmtSQL, args)
|
||||
}
|
||||
logging.LogErrorf("exec database stmt [%s] failed: %s\n %s", stmtSQL, err, logging.ShortStack())
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -1500,13 +1496,14 @@ func prepareExecInsertTx(tx *sql.Tx, stmtSQL string, args []interface{}) (err er
|
|||
|
||||
func execStmtTx(tx *sql.Tx, stmt string, args ...interface{}) (err error) {
|
||||
if _, err = tx.Exec(stmt, args...); err != nil {
|
||||
tx.Rollback()
|
||||
logging.LogErrorf("exec database stmt [%s] failed: %s\n %s", stmt, err, logging.ShortStack())
|
||||
|
||||
if strings.Contains(err.Error(), "database disk image is malformed") {
|
||||
tx.Rollback()
|
||||
closeDatabase()
|
||||
removeDatabaseFile()
|
||||
util.RemoveDatabaseFile(util.DBPath)
|
||||
logging.LogFatalf(logging.ExitCodeUnavailableDatabase, "database disk image [%s] is malformed, please restart SiYuan kernel to rebuild it\n\t%s\n\t%v", util.DBPath, stmt, args)
|
||||
}
|
||||
logging.LogErrorf("exec database stmt [%s] failed: %s\n %s", stmt, err, logging.ShortStack())
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -1559,22 +1556,6 @@ func ialAttr(ial, name string) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
func removeDatabaseFile() (err error) {
|
||||
err = os.RemoveAll(util.DBPath)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = os.RemoveAll(util.DBPath + "-shm")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = os.RemoveAll(util.DBPath + "-wal")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func closeDatabase() {
|
||||
if nil == db {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue