From ca883f5d85cc8c5243a7586ad775c63478d24728 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 4 Feb 2023 11:54:25 +0800 Subject: [PATCH 1/5] =?UTF-8?q?:art:=20=E9=87=8D=E5=BB=BA=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/appearance/langs/en_US.json | 2 +- app/appearance/langs/es_ES.json | 2 +- app/appearance/langs/fr_FR.json | 2 +- app/appearance/langs/zh_CHT.json | 2 +- app/appearance/langs/zh_CN.json | 2 +- kernel/model/box.go | 1 - 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index ba391aede..3c11ff84f 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -995,7 +995,7 @@ "105": "Corrupted data repo have been automatically reset", "106": "Maximum length is limited to 512 characters", "107": "Moving document [%s]", - "108": "Rebuild index complete", + "108": "TODO", "109": "Remove reminder completed [%s]", "110": "Renaming...", "111": "Saving document [%s]...", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 53f0e5b91..d9865401a 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -995,7 +995,7 @@ "105": "El repositorio de datos corruptos se ha restablecido automáticamente", "106": "La longitud máxima está limitada a 512 caracteres", "107": "Moviendo documento [%s]", - "108": "Reconstrucción del índice completada", + "108": "TODO", "109": "Eliminación de recordatorios completada [%s]", "110": "Renombrar...", "111": "Guardando documento [%s]...", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 2e3dc6976..6865fd911 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -995,7 +995,7 @@ "105": "Le référentiel de données corrompu a été automatiquement réinitialisé", "106": "La longueur maximale est limitée à 512 caractères", "107": "Déplacement du document [%s]", - "108": "Reconstruire l'index terminé", + "108": "TODO", "109": "Supprimer le rappel terminé [%s]", "110": "Renommer...", "111": "Enregistrement du document [%s]...", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 345a8e1cc..2c345493d 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -995,7 +995,7 @@ "105": "已經自動重置損壞的數據倉庫", "106": "最大長度限制為 512 字元", "107": "正在移動文檔 [%s]", - "108": "重建索引完畢", + "108": "TODO", "109": "移除提醒完畢 [%s]", "110": "正在重命名...", "111": "正在保存文檔 [%s]...", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index adeecada7..e4042366f 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -995,7 +995,7 @@ "105": "已经自动重置损坏的数据仓库", "106": "最大长度限制为 512 字符", "107": "正在移动文档 [%s]", - "108": "重建索引完毕", + "108": "TODO", "109": "移除提醒完毕 [%s]", "110": "正在重命名...", "111": "正在保存文档 [%s]...", diff --git a/kernel/model/box.go b/kernel/model/box.go index 7ffd2ae3e..7549cf43f 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -521,7 +521,6 @@ func fullReindex() { go func() { time.Sleep(3 * time.Second) util.PushClearMsg(msgId) - util.PushStatusBar(Conf.Language(108)) }() } From 4602976a8a4bd17b88a9a9d0311f1ecff81bc29e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 4 Feb 2023 11:57:30 +0800 Subject: [PATCH 2/5] =?UTF-8?q?:art:=20=E7=B4=A2=E5=BC=95=E8=AE=A2?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/index_fix.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go index dd94fe500..5ef745366 100644 --- a/kernel/model/index_fix.go +++ b/kernel/model/index_fix.go @@ -21,6 +21,7 @@ import ( "os" "path" "path/filepath" + "runtime" "strings" "sync" "time" @@ -148,6 +149,7 @@ func autoFixIndex() { util.PushStatusBar(Conf.Language(58)) sql.WaitForWritingDatabase() util.PushStatusBar(Conf.Language(185)) + runtime.GC() } func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) { From eea6c9468a229fdb9da3ee7a5073d1682f2ccf60 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 4 Feb 2023 14:58:19 +0800 Subject: [PATCH 3/5] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E6=A1=8C?= =?UTF-8?q?=E9=9D=A2=E7=AB=AF=E7=9B=91=E6=8E=A7=E5=89=8D=E7=AB=AF=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E8=BF=9B=E7=A8=8B=E9=80=80=E5=87=BA=E9=92=A9=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/process.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kernel/model/process.go b/kernel/model/process.go index 7b68f7439..88a725ce4 100644 --- a/kernel/model/process.go +++ b/kernel/model/process.go @@ -55,12 +55,15 @@ func HookDesktopUIProcJob() { } if 0 < util.CountSessions() { + // 如果存在活动的会话则说明 UI 进程还在运行 return } uiProcNames := []string{"siyuan", "electron"} uiProcessCount := 0 util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool { + // 从 UI 进程 ID 列表中找到 UI 进程 + uiProcessCount++ uiProcID, err := strconv.Atoi(uiProcIDArg.(string)) if nil != err { @@ -89,8 +92,24 @@ func HookDesktopUIProcJob() { } return true }) + if 1 > uiProcessCount { - noUIProcCount++ + // 如果 UI 进程 ID 列表中没有找到 UI 进程则从完整的进程列表中找 + procs, _ := goPS.Processes() + for _, proc := range procs { + procName := strings.ToLower(proc.Executable()) + uiProcOk := false + for _, name := range uiProcNames { + uiProcOk = strings.Contains(procName, name) + } + if uiProcOk { + uiProcessCount++ + } + } + + if 1 > uiProcessCount { + noUIProcCount++ + } } if 0 < noUIProcCount { From 74e7ecd5a5f9b46872afceddd8ed698b6501bf9e Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 4 Feb 2023 14:58:35 +0800 Subject: [PATCH 4/5] =?UTF-8?q?:art:=20=E5=86=85=E6=A0=B8=E5=9E=83?= =?UTF-8?q?=E5=9C=BE=E5=9B=9E=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/box.go | 4 ++-- kernel/model/import.go | 4 ++-- kernel/model/index.go | 3 ++- kernel/model/index_fix.go | 4 ++-- kernel/sql/cache.go | 4 ++-- kernel/sql/database.go | 2 ++ kernel/sql/queue.go | 6 +++--- kernel/treenode/blocktree.go | 3 ++- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kernel/model/box.go b/kernel/model/box.go index 7549cf43f..d1f5b99ce 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -25,7 +25,7 @@ import ( "os" "path" "path/filepath" - "runtime" + "runtime/debug" "sort" "strings" "sync" @@ -517,7 +517,7 @@ func fullReindex() { sql.EnableCache() treenode.SaveBlockTree(true) LoadFlashcards() - runtime.GC() + debug.FreeOSMemory() go func() { time.Sleep(3 * time.Second) util.PushClearMsg(msgId) diff --git a/kernel/model/import.go b/kernel/model/import.go index d84aeacc2..88beaf952 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -31,7 +31,7 @@ import ( "os" "path" "path/filepath" - "runtime" + "runtime/debug" "sort" "strconv" "strings" @@ -700,7 +700,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) { IncSync() util.ReloadUI() - runtime.GC() + debug.FreeOSMemory() return } diff --git a/kernel/model/index.go b/kernel/model/index.go index a84325265..533648040 100644 --- a/kernel/model/index.go +++ b/kernel/model/index.go @@ -19,6 +19,7 @@ package model import ( "fmt" "runtime" + "runtime/debug" "strings" "sync" "time" @@ -125,7 +126,7 @@ func index(boxID string) { end := time.Now() elapsed := end.Sub(start).Seconds() logging.LogInfof("rebuilt database for notebook [%s] in [%.2fs], tree [count=%d, size=%s]", box.ID, elapsed, treeCount, humanize.Bytes(uint64(treeSize))) - runtime.GC() + debug.FreeOSMemory() return } diff --git a/kernel/model/index_fix.go b/kernel/model/index_fix.go index 5ef745366..a63cd8d53 100644 --- a/kernel/model/index_fix.go +++ b/kernel/model/index_fix.go @@ -21,7 +21,7 @@ import ( "os" "path" "path/filepath" - "runtime" + "runtime/debug" "strings" "sync" "time" @@ -149,7 +149,7 @@ func autoFixIndex() { util.PushStatusBar(Conf.Language(58)) sql.WaitForWritingDatabase() util.PushStatusBar(Conf.Language(185)) - runtime.GC() + debug.FreeOSMemory() } func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) { diff --git a/kernel/sql/cache.go b/kernel/sql/cache.go index 6b4849d36..c0cc49e8f 100644 --- a/kernel/sql/cache.go +++ b/kernel/sql/cache.go @@ -17,7 +17,7 @@ package sql import ( - "runtime" + "runtime/debug" "time" "github.com/88250/lute/ast" @@ -45,7 +45,7 @@ func DisableCache() { func ClearBlockCache() { memCache.Clear() - runtime.GC() + debug.FreeOSMemory() } func putBlockCache(block *Block) { diff --git a/kernel/sql/database.go b/kernel/sql/database.go index 1d0323610..5794f5461 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -25,6 +25,7 @@ import ( "path/filepath" "regexp" "runtime" + "runtime/debug" "strings" "sync" "time" @@ -1267,6 +1268,7 @@ func closeDatabase() (err error) { } err = db.Close() + debug.FreeOSMemory() runtime.GC() // 没有这句的话文件句柄不会释放,后面就无法删除文件 return } diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go index b535bb3bd..8ab363c01 100644 --- a/kernel/sql/queue.go +++ b/kernel/sql/queue.go @@ -21,7 +21,7 @@ import ( "errors" "fmt" "path" - "runtime" + "runtime/debug" "sync" "time" @@ -128,12 +128,12 @@ func FlushQueue() { } if 16 < i && 0 == i%128 { - runtime.GC() + debug.FreeOSMemory() } } if 128 < len(ops) { - runtime.GC() + debug.FreeOSMemory() } elapsed := time.Now().Sub(start).Milliseconds() diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go index fdfeaf112..2e936f840 100644 --- a/kernel/treenode/blocktree.go +++ b/kernel/treenode/blocktree.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "runtime" + "runtime/debug" "strings" "sync" "time" @@ -380,7 +381,7 @@ func InitBlockTree(force bool) { waitGroup.Wait() p.Release() - runtime.GC() + debug.FreeOSMemory() elapsed := time.Since(start).Seconds() logging.LogInfof("read block tree [%s] to [%s], elapsed [%.2fs]", humanize.Bytes((size)), util.BlockTreePath, elapsed) return From faa4afbfe0dd9cba8160ac27087c9fd66a42ccd3 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 4 Feb 2023 15:01:57 +0800 Subject: [PATCH 5/5] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=E6=A1=8C?= =?UTF-8?q?=E9=9D=A2=E7=AB=AF=E7=9B=91=E6=8E=A7=E5=89=8D=E7=AB=AF=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E8=BF=9B=E7=A8=8B=E9=80=80=E5=87=BA=E9=92=A9=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/process.go | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/model/process.go b/kernel/model/process.go index 88a725ce4..f6937203a 100644 --- a/kernel/model/process.go +++ b/kernel/model/process.go @@ -104,6 +104,7 @@ func HookDesktopUIProcJob() { } if uiProcOk { uiProcessCount++ + break } }