mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 08:00:13 +01:00
🎨 数据订正分步执行
This commit is contained in:
parent
bf31293395
commit
daaa9e67fd
2 changed files with 26 additions and 18 deletions
|
|
@ -39,20 +39,27 @@ import (
|
||||||
|
|
||||||
// FixIndexJob 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
|
// FixIndexJob 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016
|
||||||
func FixIndexJob() {
|
func FixIndexJob() {
|
||||||
task.AppendTask(task.DatabaseIndexFix, autoFixIndex)
|
task.AppendTask(task.DatabaseIndexFix, removeDuplicateDatabaseIndex)
|
||||||
|
sql.WaitForWritingDatabase()
|
||||||
|
task.AppendTask(task.DatabaseIndexFix, fixBlockTreeByFileSys)
|
||||||
|
sql.WaitForWritingDatabase()
|
||||||
|
task.AppendTask(task.DatabaseIndexFix, fixDatabaseIndexByBlockTree)
|
||||||
|
|
||||||
|
sql.WaitForWritingDatabase()
|
||||||
|
util.PushStatusBar(Conf.Language(185))
|
||||||
|
debug.FreeOSMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
var autoFixLock = sync.Mutex{}
|
var autoFixLock = sync.Mutex{}
|
||||||
|
|
||||||
func autoFixIndex() {
|
// removeDuplicateDatabaseIndex 删除重复的数据库索引。
|
||||||
|
func removeDuplicateDatabaseIndex() {
|
||||||
defer logging.Recover()
|
defer logging.Recover()
|
||||||
|
|
||||||
autoFixLock.Lock()
|
autoFixLock.Lock()
|
||||||
defer autoFixLock.Unlock()
|
defer autoFixLock.Unlock()
|
||||||
|
|
||||||
util.PushStatusBar(Conf.Language(58))
|
util.PushStatusBar(Conf.Language(58))
|
||||||
|
|
||||||
// 去除重复的数据库块记录
|
|
||||||
duplicatedRootIDs := sql.GetDuplicatedRootIDs("blocks")
|
duplicatedRootIDs := sql.GetDuplicatedRootIDs("blocks")
|
||||||
if 1 > len(duplicatedRootIDs) {
|
if 1 > len(duplicatedRootIDs) {
|
||||||
duplicatedRootIDs = sql.GetDuplicatedRootIDs("blocks_fts")
|
duplicatedRootIDs = sql.GetDuplicatedRootIDs("blocks_fts")
|
||||||
|
|
@ -87,11 +94,16 @@ func autoFixIndex() {
|
||||||
if 0 < deletes {
|
if 0 < deletes {
|
||||||
logging.LogWarnf("exist more than one tree duplicated [%d], reindex it", deletes)
|
logging.LogWarnf("exist more than one tree duplicated [%d], reindex it", deletes)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fixBlockTreeByFileSys 通过文件系统订正块树。
|
||||||
|
func fixBlockTreeByFileSys() {
|
||||||
|
defer logging.Recover()
|
||||||
|
|
||||||
|
autoFixLock.Lock()
|
||||||
|
defer autoFixLock.Unlock()
|
||||||
|
|
||||||
util.PushStatusBar(Conf.Language(58))
|
util.PushStatusBar(Conf.Language(58))
|
||||||
sql.WaitForWritingDatabase()
|
|
||||||
util.PushStatusBar(Conf.Language(58))
|
|
||||||
// 根据文件系统补全块树
|
|
||||||
boxes := Conf.GetOpenedBoxes()
|
boxes := Conf.GetOpenedBoxes()
|
||||||
for _, box := range boxes {
|
for _, box := range boxes {
|
||||||
boxPath := filepath.Join(util.DataDir, box.ID)
|
boxPath := filepath.Join(util.DataDir, box.ID)
|
||||||
|
|
@ -130,26 +142,23 @@ func autoFixIndex() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
util.PushStatusBar(Conf.Language(58))
|
|
||||||
sql.WaitForWritingDatabase()
|
|
||||||
util.PushStatusBar(Conf.Language(58))
|
|
||||||
// 清理已关闭的笔记本块树
|
// 清理已关闭的笔记本块树
|
||||||
boxes = Conf.GetClosedBoxes()
|
boxes = Conf.GetClosedBoxes()
|
||||||
for _, box := range boxes {
|
for _, box := range boxes {
|
||||||
treenode.RemoveBlockTreesByBoxID(box.ID)
|
treenode.RemoveBlockTreesByBoxID(box.ID)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 对比块树和数据库并订正数据库
|
// fixDatabaseIndexByBlockTree 通过块树订正数据库索引。
|
||||||
|
func fixDatabaseIndexByBlockTree() {
|
||||||
|
defer logging.Recover()
|
||||||
|
|
||||||
|
util.PushStatusBar(Conf.Language(58))
|
||||||
rootUpdatedMap := treenode.GetRootUpdated()
|
rootUpdatedMap := treenode.GetRootUpdated()
|
||||||
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
||||||
if nil == err {
|
if nil == err {
|
||||||
reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap)
|
reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
util.PushStatusBar(Conf.Language(58))
|
|
||||||
sql.WaitForWritingDatabase()
|
|
||||||
util.PushStatusBar(Conf.Language(185))
|
|
||||||
debug.FreeOSMemory()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) {
|
func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) {
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,6 @@ var uniqueActions = []string{
|
||||||
RepoCheckout,
|
RepoCheckout,
|
||||||
DatabaseIndexFull,
|
DatabaseIndexFull,
|
||||||
DatabaseIndexCommit,
|
DatabaseIndexCommit,
|
||||||
DatabaseIndexFix,
|
|
||||||
OCRImage,
|
OCRImage,
|
||||||
HistoryGenerateDoc,
|
HistoryGenerateDoc,
|
||||||
DatabaseIndexEmbedBlock,
|
DatabaseIndexEmbedBlock,
|
||||||
|
|
@ -197,7 +196,7 @@ func execTask(task *Task) {
|
||||||
|
|
||||||
currentTaskAction = task.Action
|
currentTaskAction = task.Action
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
ch := make(chan bool, 1)
|
ch := make(chan bool, 1)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue