Explorar el Código

Merge remote-tracking branch 'origin/dev' into dev

Vanessa hace 2 años
padre
commit
ce45575740
Se han modificado 5 ficheros con 32 adiciones y 54 borrados
  1. 0 2
      kernel/go.mod
  2. 0 6
      kernel/go.sum
  3. 29 20
      kernel/job/cron.go
  4. 2 3
      kernel/model/import.go
  5. 1 23
      kernel/task/queue.go

+ 0 - 2
kernel/go.mod

@@ -68,7 +68,6 @@ require (
 	github.com/dlclark/regexp2 v1.8.0 // indirect
 	github.com/dsnet/compress v0.0.1 // indirect
 	github.com/gin-contrib/sse v0.1.0 // indirect
-	github.com/go-co-op/gocron v1.18.0 // indirect
 	github.com/go-ole/go-ole v1.2.6 // indirect
 	github.com/go-playground/locales v0.14.1 // indirect
 	github.com/go-playground/universal-translator v0.18.0 // indirect
@@ -113,7 +112,6 @@ require (
 	github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
 	github.com/qiniu/go-sdk/v7 v7.14.0 // indirect
 	github.com/restic/chunker v0.4.0 // indirect
-	github.com/robfig/cron/v3 v3.0.1 // indirect
 	github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
 	github.com/shopspring/decimal v1.3.1 // indirect
 	github.com/spf13/cast v1.5.0 // indirect

+ 0 - 6
kernel/go.sum

@@ -108,8 +108,6 @@ github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR
 github.com/gin-gonic/gin v1.8.2 h1:UzKToD9/PoFj/V4rvlKqTRKnQYyz8Sc1MJlv4JHPtvY=
 github.com/gin-gonic/gin v1.8.2/go.mod h1:qw5AYuDrzRTnhvusDsrov+fDIxp9Dleuu12h8nfB398=
 github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
-github.com/go-co-op/gocron v1.18.0 h1:SxTyJ5xnSN4byCq7b10LmmszFdxQlSQJod8s3gbnXxA=
-github.com/go-co-op/gocron v1.18.0/go.mod h1:sD/a0Aadtw5CpflUJ/lpP9Vfdk979Wl1Sg33HPHg0FY=
 github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
 github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
 github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
@@ -336,8 +334,6 @@ github.com/radovskyb/watcher v1.0.7/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm
 github.com/restic/chunker v0.4.0 h1:YUPYCUn70MYP7VO4yllypp2SjmsRhRJaad3xKu1QFRw=
 github.com/restic/chunker v0.4.0/go.mod h1:z0cH2BejpW636LXw0R/BGyv+Ey8+m9QGiOanDHItzyw=
 github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
-github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
-github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
 github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
 github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
 github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
@@ -379,8 +375,6 @@ github.com/siyuan-note/dejavu v0.0.0-20230117131301-821aa3adc1e7 h1:rlsamJZ3a7kK
 github.com/siyuan-note/dejavu v0.0.0-20230117131301-821aa3adc1e7/go.mod h1:5LbmFNnDo8TZZZcu+vkeW/Gi+yBdVn0v64x0ztoqyfg=
 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
-github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=
-github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI=
 github.com/siyuan-note/eventbus v0.0.0-20230126092943-c6bf51e65ae2 h1:njoj0265FOHRjF/O1aWDzdwEdYdLTZwhbuPd/hoLJT0=
 github.com/siyuan-note/eventbus v0.0.0-20230126092943-c6bf51e65ae2/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI=
 github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e h1:i3RKrdrddr4AuaHJtoWYAEVNuR7Y9wIsEqPmuFFbJC4=

+ 29 - 20
kernel/job/cron.go

@@ -17,31 +17,40 @@
 package job
 
 import (
+	"time"
+
+	"github.com/siyuan-note/logging"
 	"github.com/siyuan-note/siyuan/kernel/model"
 	"github.com/siyuan-note/siyuan/kernel/sql"
 	"github.com/siyuan-note/siyuan/kernel/task"
-	"github.com/siyuan-note/siyuan/kernel/util"
-	"time"
-
-	"github.com/go-co-op/gocron"
 	"github.com/siyuan-note/siyuan/kernel/treenode"
+	"github.com/siyuan-note/siyuan/kernel/util"
 )
 
 func StartCron() {
-	s := gocron.NewScheduler(time.Local)
-	s.Every(1).Seconds().Do(task.ExecTaskJob)
-	s.Every(5).Seconds().Do(task.StatusJob)
-	s.Every(1).Second().Do(treenode.SaveBlockTreeJob)
-	s.Every(5).Seconds().Do(model.SyncDataJob)
-	s.Every(2).Hours().Do(model.StatJob)
-	s.Every(2).Hours().Do(model.RefreshCheckJob)
-	s.Every(3).Seconds().Do(model.FlushUpdateRefTextRenameDocJob)
-	s.Every(2).Seconds().Do(model.FlushTxJob)
-	s.Every(util.SQLFlushInterval).Do(sql.FlushTxJob)
-	s.Every(10).Minutes().Do(model.FixIndexJob)
-	s.Every(10).Minutes().Do(model.IndexEmbedBlockJob)
-	s.Every(7).Seconds().Do(model.OCRAssetsJob)
-	s.Every(7).Seconds().Do(model.FlushAssetsTextsJob)
-	s.Every(30).Seconds().Do(model.HookDesktopUIProcJob)
-	s.StartAsync()
+	go every(100*time.Millisecond, task.ExecTaskJob)
+	go every(5*time.Second, task.StatusJob)
+	go every(3*time.Second, treenode.SaveBlockTreeJob)
+	go every(5*time.Second, model.SyncDataJob)
+	go every(2*time.Hour, model.StatJob)
+	go every(2*time.Hour, model.RefreshCheckJob)
+	go every(3*time.Second, model.FlushUpdateRefTextRenameDocJob)
+	go every(2*time.Second, model.FlushTxJob)
+	go every(util.SQLFlushInterval, sql.FlushTxJob)
+	go every(10*time.Minute, model.FixIndexJob)
+	go every(10*time.Minute, model.IndexEmbedBlockJob)
+	go every(12*time.Second, model.OCRAssetsJob)
+	go every(12*time.Second, model.FlushAssetsTextsJob)
+	go every(30*time.Second, model.HookDesktopUIProcJob)
+}
+
+func every(interval time.Duration, f func()) {
+	for {
+		func() {
+			defer logging.Recover()
+			f()
+		}()
+
+		time.Sleep(interval)
+	}
 }

+ 2 - 3
kernel/model/import.go

@@ -45,7 +45,6 @@ import (
 	"github.com/88250/lute/render"
 	"github.com/siyuan-note/filelock"
 	"github.com/siyuan-note/logging"
-	"github.com/siyuan-note/siyuan/kernel/filesys"
 	"github.com/siyuan-note/siyuan/kernel/sql"
 	"github.com/siyuan-note/siyuan/kernel/treenode"
 	"github.com/siyuan-note/siyuan/kernel/util"
@@ -524,7 +523,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
 			hPath = strings.TrimSuffix(hPath, ext)
 			if info.IsDir() {
 				tree = treenode.NewTree(boxID, targetPath, hPath, title)
-				if err = filesys.WriteTree(tree); nil != err {
+				if err = indexWriteJSONQueue(tree); nil != err {
 					return io.EOF
 				}
 				return nil
@@ -614,7 +613,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
 
 			i++
 			if 0 == i%4 {
-				util.PushEndlessProgress(fmt.Sprintf(Conf.Language(66), util.ShortPathForBootingDisplay(tree.Path)))
+				util.PushEndlessProgress(fmt.Sprintf(Conf.Language(66), fmt.Sprintf("%d ", i)+util.ShortPathForBootingDisplay(tree.Path)))
 			}
 			return nil
 		})

+ 1 - 23
kernel/task/queue.go

@@ -47,7 +47,6 @@ func PrependTask(action string, handler interface{}, args ...interface{}) {
 		return
 	}
 
-	cancelTask(action, args...)
 	taskQueue = append([]*Task{newTask(action, handler, args...)}, taskQueue...)
 }
 
@@ -60,30 +59,9 @@ func AppendTask(action string, handler interface{}, args ...interface{}) {
 		return
 	}
 
-	cancelTask(action, args...)
 	taskQueue = append(taskQueue, newTask(action, handler, args...))
 }
 
-func cancelTask(action string, args ...interface{}) {
-	for i := len(taskQueue) - 1; i >= 0; i-- {
-		task := taskQueue[i]
-		if action == task.Action {
-			if len(task.Args) != len(args) {
-				continue
-			}
-
-			for j, arg := range args {
-				if arg != task.Args[j] {
-					continue
-				}
-			}
-
-			taskQueue = append(taskQueue[:i], taskQueue[i+1:]...)
-			break
-		}
-	}
-}
-
 func newTask(action string, handler interface{}, args ...interface{}) *Task {
 	return &Task{
 		Action:  action,
@@ -181,7 +159,7 @@ func execTask(task *Task) {
 		}
 	}
 
-	ctx, cancel := context.WithTimeout(context.Background(), time.Second*12)
+	ctx, cancel := context.WithTimeout(context.Background(), time.Second*7)
 	defer cancel()
 	ch := make(chan bool, 1)
 	go func() {