Skip to content

Commit

Permalink
🐛 Index fixing should not be performed before data synchronization #1…
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Mar 27, 2024
1 parent 2c1e896 commit 0322e02
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion kernel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func main() {
util.PushClearAllMsg()

job.StartCron()
go model.CheckIndex()
go model.AutoGenerateDocHistory()
go cache.LoadAssets()
go util.CheckFileSysStatus()
Expand Down
1 change: 0 additions & 1 deletion kernel/mobile/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func StartKernel(container, appDir, workspaceBaseDir, timezoneID, localIPs, lang
util.PushClearAllMsg()

job.StartCron()
go model.CheckIndex()
go model.AutoGenerateDocHistory()
go cache.LoadAssets()
}()
Expand Down
18 changes: 16 additions & 2 deletions kernel/model/index_fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"runtime/debug"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/88250/gulu"
Expand All @@ -40,8 +41,18 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)

// CheckIndex 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016 https://github.com/siyuan-note/siyuan/issues/10563
func CheckIndex() {
var (
checkIndexPerformed = atomic.Bool{}
)

// checkIndex 自动校验数据库索引,仅在数据同步执行完成后执行一次。
func checkIndex() {
if checkIndexPerformed.Load() {
return
}

logging.LogInfof("start checking index...")

task.AppendTask(task.DatabaseIndexFix, removeDuplicateDatabaseIndex)
sql.WaitForWritingDatabase()

Expand All @@ -61,6 +72,9 @@ func CheckIndex() {
util.PushStatusBar(Conf.Language(185))
})
debug.FreeOSMemory()
logging.LogInfof("finish checking index")

checkIndexPerformed.Store(true)
}

var autoFixLock = sync.Mutex{}
Expand Down
3 changes: 3 additions & 0 deletions kernel/model/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,9 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
autoSyncErrCount = 0

processSyncMergeResult(exit, byHand, mergeResult, trafficStat, "a", elapsed)

// 首次数据同步执行完成后再执行索引订正 Index fixing should not be performed before data synchronization https://github.com/siyuan-note/siyuan/issues/10761
checkIndex()
return
}

Expand Down

0 comments on commit 0322e02

Please sign in to comment.