♻️ 改进后台任务判断重复

This commit is contained in:
Liang Ding 2023-01-28 16:16:24 +08:00
parent 83afeb5a8b
commit 23df378a32
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 8 additions and 4 deletions

View file

@ -157,7 +157,7 @@ func loadTreeByBlockID(id string) (ret *parse.Tree, err error) {
bt := treenode.GetBlockTree(id) bt := treenode.GetBlockTree(id)
if nil == bt { if nil == bt {
if task.ContainIndexTask() { if task.ContainIndexTask(task.DatabaseIndex, task.DatabaseIndexFull) {
err = ErrIndexing err = ErrIndexing
return return
} }

View file

@ -18,12 +18,13 @@ package task
import ( import (
"context" "context"
"github.com/siyuan-note/siyuan/kernel/util"
"reflect" "reflect"
"sync" "sync"
"time" "time"
"github.com/88250/gulu"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
) )
var ( var (
@ -84,9 +85,12 @@ const (
ReloadUI = "task.reload.ui" // 重载 UI ReloadUI = "task.reload.ui" // 重载 UI
) )
func ContainIndexTask() bool { func ContainIndexTask(action string, moreActions ...string) bool {
actions := append(moreActions, action)
actions = gulu.Str.RemoveDuplicatedElem(actions)
for _, task := range taskQueue { for _, task := range taskQueue {
if DatabaseIndex == task.Action || DatabaseIndexFull == task.Action { if gulu.Str.Contains(task.Action, actions) {
return true return true
} }
} }