An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 内核垃圾回收
Liang Ding74e7ecd5a5f9
diff --git a/kernel/model/box.go b/kernel/model/box.goindex 7549cf43f8..d1f5b99ce7 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.goindex d84aeacc25..88beaf9523 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.goindex a84325265d..533648040d 100644--- a/kernel/model/index.go+++ b/kernel/model/index.go@@ -19,6 +19,7 @@ package modelimport ("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.goindex 5ef7453660..a63cd8d533 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.goindex 6b4849d36e..c0cc49e8f7 100644--- a/kernel/sql/cache.go+++ b/kernel/sql/cache.go@@ -17,7 +17,7 @@package sqlimport (- "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.goindex 1d0323610b..5794f54614 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.goindex b535bb3bde..8ab363c019 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.goindex fdfeaf1120..2e936f8409 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