This commit is contained in:
Daniel 2024-06-27 21:29:31 +08:00
parent c9d3a50fd4
commit ed5c4738f9
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 38 additions and 22 deletions

View file

@ -54,7 +54,7 @@ require (
github.com/shirou/gopsutil/v3 v3.24.5
github.com/siyuan-note/dejavu v0.0.0-20240626145351-e4f9b0821aaf
github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4
github.com/siyuan-note/eventbus v0.0.0-20240318125243-801c98e8f025
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97
github.com/siyuan-note/filelock v0.0.0-20240505150405-3de3a406d257
github.com/siyuan-note/httpclient v0.0.0-20240626145026-29585d45a51c
github.com/siyuan-note/logging v0.0.0-20240505035402-6430d57006a2

View file

@ -357,8 +357,8 @@ github.com/siyuan-note/dejavu v0.0.0-20240626145351-e4f9b0821aaf h1:rul3+iFekIhj
github.com/siyuan-note/dejavu v0.0.0-20240626145351-e4f9b0821aaf/go.mod h1:fEgyP8xD6Do5ogMn9hFCz0e4IQQVamwM2uX96bOCpPQ=
github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4 h1:kJaw5L/evyW6LcB9IQT8PR4ppx8JVqOFP9Ix3rfwSrc=
github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4/go.mod h1:UYcCCY+0wh+GmUoDOaO63j1sV5lgy7laLAk1XhEiUis=
github.com/siyuan-note/eventbus v0.0.0-20240318125243-801c98e8f025 h1:crQmKw5vZz3MljAP/xKMWY/rksMX634jJK9kcsOIbkw=
github.com/siyuan-note/eventbus v0.0.0-20240318125243-801c98e8f025/go.mod h1:1/nGgthl89FPA7GzAcEWKl6zRRnfgyTjzLZj9bW7kuw=
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97 h1:lM5v8BfNtbOL5jYwhCdMYBcYtr06IYBKjjSLAPMKTM8=
github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97/go.mod h1:1/nGgthl89FPA7GzAcEWKl6zRRnfgyTjzLZj9bW7kuw=
github.com/siyuan-note/filelock v0.0.0-20240505150405-3de3a406d257 h1:lA6qBehxciYKye8LpP59LHGC8DQkkJkg7AYA4VoF+g8=
github.com/siyuan-note/filelock v0.0.0-20240505150405-3de3a406d257/go.mod h1:vUXGLmTVIg5trcnNWGkMCwc3EuIJaXXx3hQzgno1Hn4=
github.com/siyuan-note/httpclient v0.0.0-20240626145026-29585d45a51c h1:E6W4x2GL+7jHsfkPEldvosWNl7hxtRHJjgGVhHHywn4=

View file

@ -81,7 +81,7 @@ type AppConf struct {
ShowChangelog bool `json:"showChangelog"` // 是否显示版本更新日志
CloudRegion int `json:"cloudRegion"` // 云端区域0中国大陆1北美
Snippet *conf.Snpt `json:"snippet"` // 代码片段
State int `json:"state"` // 运行状态0已经正常退出1运行中
DataIndexState int `json:"dataIndexState"` // 数据索引状态0已索引1未索引
m *sync.Mutex
}
@ -464,8 +464,8 @@ func InitConf() {
Conf.LocalIPs = util.GetLocalIPs()
if 1 == Conf.State {
// 上次未正常退出
if 1 == Conf.DataIndexState {
// 上次未正常完成数据索引
go func() {
util.WaitForUILoaded()
time.Sleep(2 * time.Second)
@ -477,7 +477,7 @@ func InitConf() {
}()
}
Conf.State = 1 // 运行中
Conf.DataIndexState = 0
Conf.Save()
logging.SetLogLevel(Conf.LogLevel)
@ -716,7 +716,6 @@ func (conf *AppConf) save0(data []byte) {
}
func (conf *AppConf) Close() {
conf.State = 0 // 已经正常退出
conf.Save()
}

View file

@ -429,4 +429,14 @@ func subscribeSQLEvents() {
util.SetBootDetails(msg)
util.ContextPushMsg(context, msg)
})
eventbus.Subscribe(eventbus.EvtSQLIndexChanged, func() {
Conf.DataIndexState = 1
Conf.Save()
})
eventbus.Subscribe(eventbus.EvtSQLIndexFlushed, func() {
Conf.DataIndexState = 0
Conf.Save()
})
}

View file

@ -164,6 +164,8 @@ func FlushQueue() {
// Push database index commit event https://github.com/siyuan-note/siyuan/issues/8814
util.BroadcastByType("main", "databaseIndexCommit", 0, "", nil)
eventbus.Publish(eventbus.EvtSQLIndexFlushed)
}
func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (err error) {
@ -219,7 +221,7 @@ func IndexNodeQueue(id string) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func BatchRemoveAssetsQueue(hashes []string) {
@ -231,7 +233,7 @@ func BatchRemoveAssetsQueue(hashes []string) {
defer dbQueueLock.Unlock()
newOp := &dbQueueOperation{removeAssetHashes: hashes, inQueueTime: time.Now(), action: "delete_assets"}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func UpdateBlockContentQueue(block *Block) {
@ -245,7 +247,7 @@ func UpdateBlockContentQueue(block *Block) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func DeleteRefsTreeQueue(tree *parse.Tree) {
@ -259,7 +261,7 @@ func DeleteRefsTreeQueue(tree *parse.Tree) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func UpdateRefsTreeQueue(tree *parse.Tree) {
@ -273,7 +275,7 @@ func UpdateRefsTreeQueue(tree *parse.Tree) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func DeleteBoxRefsQueue(boxID string) {
@ -287,7 +289,7 @@ func DeleteBoxRefsQueue(boxID string) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func DeleteBoxQueue(boxID string) {
@ -301,7 +303,7 @@ func DeleteBoxQueue(boxID string) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func IndexTreeQueue(tree *parse.Tree) {
@ -315,7 +317,7 @@ func IndexTreeQueue(tree *parse.Tree) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func UpsertTreeQueue(tree *parse.Tree) {
@ -329,7 +331,7 @@ func UpsertTreeQueue(tree *parse.Tree) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func RenameTreeQueue(tree *parse.Tree) {
@ -347,7 +349,7 @@ func RenameTreeQueue(tree *parse.Tree) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func RenameSubTreeQueue(tree *parse.Tree) {
@ -365,7 +367,7 @@ func RenameSubTreeQueue(tree *parse.Tree) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func RemoveTreeQueue(rootID string) {
@ -379,7 +381,7 @@ func RemoveTreeQueue(rootID string) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func BatchRemoveTreeQueue(rootIDs []string) {
@ -391,7 +393,7 @@ func BatchRemoveTreeQueue(rootIDs []string) {
defer dbQueueLock.Unlock()
newOp := &dbQueueOperation{removeTreeIDs: rootIDs, inQueueTime: time.Now(), action: "delete_ids"}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func RemoveTreePathQueue(treeBox, treePathPrefix string) {
@ -405,7 +407,7 @@ func RemoveTreePathQueue(treeBox, treePathPrefix string) {
return
}
}
operationQueue = append(operationQueue, newOp)
appendOperation(newOp)
}
func getOperations() (ops []*dbQueueOperation) {
@ -416,3 +418,8 @@ func getOperations() (ops []*dbQueueOperation) {
operationQueue = nil
return
}
func appendOperation(op *dbQueueOperation) {
operationQueue = append(operationQueue, op)
eventbus.Publish(eventbus.EvtSQLIndexChanged)
}