浏览代码

:art: 改进状态栏显示后台任务执行计数 Fix https://github.com/siyuan-note/siyuan/issues/7398

Liang Ding 2 年之前
父节点
当前提交
7b41e698e1
共有 3 个文件被更改,包括 23 次插入9 次删除
  1. 3 3
      kernel/model/index.go
  2. 9 2
      kernel/sql/queue.go
  3. 11 4
      kernel/sql/queue_history.go

+ 3 - 3
kernel/model/index.go

@@ -268,7 +268,7 @@ func init() {
 			return
 		}
 
-		current := context["current"].(int) + 1
+		current := context["current"].(int)
 		total := context["total"]
 		msg := fmt.Sprintf(Conf.Language(90), current, total, blockCount, hash)
 		util.SetBootDetails(msg)
@@ -280,7 +280,7 @@ func init() {
 			return
 		}
 
-		current := context["current"].(int) + 1
+		current := context["current"].(int)
 		total := context["total"]
 		msg := fmt.Sprintf(Conf.Language(93), current, total, rootID)
 		util.SetBootDetails(msg)
@@ -292,7 +292,7 @@ func init() {
 			return
 		}
 
-		current := context["current"].(int) + 1
+		current := context["current"].(int)
 		total := context["total"]
 		msg := fmt.Sprintf(Conf.Language(191), current, total)
 		util.SetBootDetails(msg)

+ 9 - 2
kernel/sql/queue.go

@@ -110,6 +110,12 @@ func FlushQueue() {
 		defer enableCache()
 	}
 
+	groupOpsTotal := map[string]int{}
+	for _, op := range ops {
+		groupOpsTotal[op.action]++
+	}
+
+	groupOpsCurrent := map[string]int{}
 	for i, op := range ops {
 		if util.IsExiting {
 			return
@@ -120,8 +126,9 @@ func FlushQueue() {
 			return
 		}
 
-		context["current"] = i
-		context["total"] = total
+		groupOpsCurrent[op.action]++
+		context["current"] = groupOpsCurrent[op.action]
+		context["total"] = groupOpsTotal[op.action]
 		if err = execOp(op, tx, context); nil != err {
 			tx.Rollback()
 			logging.LogErrorf("queue operation failed: %s", err)

+ 11 - 4
kernel/sql/queue_history.go

@@ -59,7 +59,13 @@ func FlushHistoryQueue() {
 	defer txLock.Unlock()
 	start := time.Now()
 
-	total := len(ops)
+	groupOpsTotal := map[string]int{}
+	for _, op := range ops {
+		groupOpsTotal[op.action]++
+	}
+
+	context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
+	groupOpsCurrent := map[string]int{}
 	for i, op := range ops {
 		if util.IsExiting {
 			return
@@ -70,9 +76,10 @@ func FlushHistoryQueue() {
 			return
 		}
 
-		context := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
-		context["current"] = i
-		context["total"] = total
+		groupOpsCurrent[op.action]++
+		context["current"] = groupOpsCurrent[op.action]
+		context["total"] = groupOpsTotal[op.action]
+
 		if err = execHistoryOp(op, tx, context); nil != err {
 			tx.Rollback()
 			logging.LogErrorf("queue operation failed: %s", err)