Parcourir la source

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

Vanessa il y a 2 ans
Parent
commit
258acc1142

+ 4 - 4
app/electron/main.js

@@ -131,8 +131,8 @@ const boot = () => {
   let defaultHeight
   let workArea
   try {
-    defaultWidth = screen.getPrimaryDisplay().size.width * 4 / 5
-    defaultHeight = screen.getPrimaryDisplay().workAreaSize.height * 4 / 5
+    defaultWidth = screen.getPrimaryDisplay().size.width
+    defaultHeight = screen.getPrimaryDisplay().workAreaSize.height
     workArea = screen.getPrimaryDisplay().workArea
   } catch (e) {
     console.error(e)
@@ -807,8 +807,8 @@ app.whenReady().then(() => {
 
   if (firstOpen) {
     const firstOpenWindow = new BrowserWindow({
-      width: screen.getPrimaryDisplay().size.width / 2,
-      height: screen.getPrimaryDisplay().workAreaSize.height / 2,
+      width: screen.getPrimaryDisplay().size.width * 0.6,
+      height: screen.getPrimaryDisplay().workAreaSize.height * 0.8,
       frame: false,
       icon: path.join(appDir, 'stage', 'icon-large.png'),
       transparent: 'linux' !== process.platform,

+ 1 - 0
kernel/job/cron.go

@@ -45,6 +45,7 @@ func StartCron() {
 }
 
 func every(interval time.Duration, f func()) {
+	util.RandomSleep(50, 200)
 	for {
 		func() {
 			defer logging.Recover()

+ 29 - 26
kernel/model/ocr.go

@@ -32,34 +32,37 @@ func autoOCRAssets() {
 
 	assetsPath := util.GetDataAssetsAbsPath()
 	assets := getUnOCRAssetsAbsPaths()
-
-	poolSize := runtime.NumCPU()
-	if 4 < poolSize {
-		poolSize = 4
-	}
-	waitGroup := &sync.WaitGroup{}
-	p, _ := ants.NewPoolWithFunc(poolSize, func(arg interface{}) {
-		defer waitGroup.Done()
-
-		assetAbsPath := arg.(string)
-		text := util.Tesseract(assetAbsPath)
-		p := strings.TrimPrefix(assetAbsPath, assetsPath)
-		p = "assets" + filepath.ToSlash(p)
-		util.AssetsTextsLock.Lock()
-		util.AssetsTexts[p] = text
-		util.AssetsTextsLock.Unlock()
-		util.AssetsTextsChanged = true
-	})
-	for i, assetAbsPath := range assets {
-		waitGroup.Add(1)
-		p.Invoke(assetAbsPath)
-
-		if 63 <= i { // 一次任务中最多处理 64 张图片,防止卡顿
-			break
+	if 0 < len(assets) {
+		poolSize := runtime.NumCPU()
+		if 4 < poolSize {
+			poolSize = 4
+		}
+		waitGroup := &sync.WaitGroup{}
+		p, _ := ants.NewPoolWithFunc(poolSize, func(arg interface{}) {
+			defer waitGroup.Done()
+
+			assetAbsPath := arg.(string)
+			text := util.Tesseract(assetAbsPath)
+			p := strings.TrimPrefix(assetAbsPath, assetsPath)
+			p = "assets" + filepath.ToSlash(p)
+			util.AssetsTextsLock.Lock()
+			util.AssetsTexts[p] = text
+			util.AssetsTextsLock.Unlock()
+			util.AssetsTextsChanged = true
+		})
+
+		for i, assetAbsPath := range assets {
+			waitGroup.Add(1)
+			p.Invoke(assetAbsPath)
+
+			if 63 <= i { // 一次任务中最多处理 64 张图片,防止卡顿
+				break
+			}
 		}
+
+		waitGroup.Wait()
+		p.Release()
 	}
-	waitGroup.Wait()
-	p.Release()
 
 	cleanNotExistAssetsTexts()
 }

+ 4 - 0
kernel/model/process.go

@@ -51,6 +51,10 @@ func HookDesktopUIProcJob() {
 		return
 	}
 
+	if 0 < util.CountSessions() {
+		return
+	}
+
 	uiProcNames := []string{"siyuan", "electron"}
 	existUIProc := false
 	util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {

+ 4 - 2
kernel/model/sync.go

@@ -47,9 +47,11 @@ var (
 )
 
 func SyncDataJob() {
-	if time.Now().After(syncPlanTime) {
-		SyncData(false, false, false)
+	if time.Now().Before(syncPlanTime) {
+		return
 	}
+
+	SyncData(false, false, false)
 }
 
 func BootSyncData() {

+ 2 - 2
kernel/sql/queue.go

@@ -135,8 +135,8 @@ func FlushQueue() {
 	}
 
 	elapsed := time.Now().Sub(start).Milliseconds()
-	if 5000 < elapsed {
-		logging.LogInfof("op tx [%dms]", elapsed)
+	if 7000 < elapsed {
+		logging.LogInfof("database op tx [%dms]", elapsed)
 	}
 }
 

+ 8 - 6
kernel/task/queue.go

@@ -97,21 +97,23 @@ func StatusJob() {
 	tasks := taskQueue
 	data := map[string]interface{}{}
 	var items []map[string]interface{}
+	count := map[string]int{}
 	for _, task := range tasks {
-		if OCRImage == task.Action || DatabaseIndexEmbedBlock == task.Action {
+		actionLangs := util.TaskActionLangs[util.Lang]
+		action := task.Action
+		if c := count[action]; 3 < c {
+			logging.LogWarnf("too many tasks [%s], ignore show its status", action)
 			continue
 		}
+		count[action]++
 
-		actionLangs := util.TaskActionLangs[util.Lang]
-		action := task.Action
 		if nil != actionLangs {
 			if label := actionLangs[task.Action]; nil != label {
 				action = label.(string)
 			}
 		}
-		item := map[string]interface{}{
-			"action": action,
-		}
+
+		item := map[string]interface{}{"action": action}
 		items = append(items, item)
 	}
 	if 1 > len(items) {