From 96c2093bd8c66f35c53c1767438deb000ad86997 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Mon, 29 Dec 2025 22:36:30 +0800
Subject: [PATCH] :art: Supports configuring the maximum number of `Recent
documents` to be listed https://github.com/siyuan-note/siyuan/issues/16720
Signed-off-by: Daniel <845765@qq.com>
---
app/src/mobile/settings/fileTree.ts | 7 +++++++
kernel/api/setting.go | 4 ++++
kernel/conf/filetree.go | 2 ++
kernel/model/conf.go | 4 ++--
kernel/model/storage.go | 13 ++++++++++---
5 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/app/src/mobile/settings/fileTree.ts b/app/src/mobile/settings/fileTree.ts
index f73fbaba7..2c24ec6a4 100644
--- a/app/src/mobile/settings/fileTree.ts
+++ b/app/src/mobile/settings/fileTree.ts
@@ -54,6 +54,12 @@ export const initFileTree = () => {
${window.siyuan.languages.fileTree17}
+
+ ${window.siyuan.languages.recentDocsMaxCount}
+
+
+
${window.siyuan.languages.recentDocsMaxCountTip}
+
${window.siyuan.languages.fileTree12}
@@ -90,6 +96,7 @@ export const initFileTree = () => {
createDocAtTop: (modelMainElement.querySelector("#createDocAtTop") as HTMLInputElement).checked,
largeFileWarningSize: parseInt((modelMainElement.querySelector("#largeFileWarningSize") as HTMLInputElement).value),
maxListCount: parseInt((modelMainElement.querySelector("#maxListCount") as HTMLInputElement).value),
+ recentDocsMaxListCount: parseInt((modelMainElement.querySelector("#recentDocsMaxListCount") as HTMLInputElement).value),
maxOpenTabCount: window.siyuan.config.fileTree.maxOpenTabCount,
}, response => {
window.siyuan.config.fileTree = response.data;
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index dea84ec12..0362a1fbd 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -423,6 +423,10 @@ func setFiletree(c *gin.Context) {
if 32 < fileTree.MaxOpenTabCount {
fileTree.MaxOpenTabCount = 32
}
+ if conf.MaxFileTreeRecentDocsListCount < fileTree.RecentDocsMaxListCount {
+ fileTree.RecentDocsMaxListCount = conf.MaxFileTreeRecentDocsListCount
+ }
+
model.Conf.FileTree = fileTree
model.Conf.Save()
diff --git a/kernel/conf/filetree.go b/kernel/conf/filetree.go
index 62add8ed9..31f7e430f 100644
--- a/kernel/conf/filetree.go
+++ b/kernel/conf/filetree.go
@@ -53,3 +53,5 @@ func NewFileTree() *FileTree {
CreateDocAtTop: func() *bool { b := false; return &b }(),
}
}
+
+const MaxFileTreeRecentDocsListCount = 256
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 6d69ebe82..96ddc99f1 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -239,8 +239,8 @@ func InitConf() {
if 1 > Conf.FileTree.RecentDocsMaxListCount {
Conf.FileTree.RecentDocsMaxListCount = 32
}
- if 256 < Conf.FileTree.RecentDocsMaxListCount {
- Conf.FileTree.RecentDocsMaxListCount = 256
+ if conf.MaxFileTreeRecentDocsListCount < Conf.FileTree.RecentDocsMaxListCount {
+ Conf.FileTree.RecentDocsMaxListCount = conf.MaxFileTreeRecentDocsListCount
}
util.CurrentCloudRegion = Conf.CloudRegion
diff --git a/kernel/model/storage.go b/kernel/model/storage.go
index 604884c05..21e1e345d 100644
--- a/kernel/model/storage.go
+++ b/kernel/model/storage.go
@@ -99,8 +99,8 @@ func setRecentDocByTree(tree *parse.Tree) {
}
recentDocs = append([]*RecentDoc{recentDoc}, recentDocs...)
- if Conf.FileTree.RecentDocsMaxListCount < len(recentDocs) {
- recentDocs = recentDocs[:Conf.FileTree.RecentDocsMaxListCount]
+ if 256 < len(recentDocs) {
+ recentDocs = recentDocs[:256]
}
err = setRecentDocs(recentDocs)
@@ -192,7 +192,14 @@ func UpdateRecentDocCloseTime(rootID string) (err error) {
func GetRecentDocs(sortBy string) (ret []*RecentDoc, err error) {
recentDocLock.Lock()
defer recentDocLock.Unlock()
- return getRecentDocs(sortBy)
+ ret, err = getRecentDocs(sortBy)
+ if err != nil {
+ return
+ }
+ if len(ret) > Conf.FileTree.RecentDocsMaxListCount {
+ ret = ret[:Conf.FileTree.RecentDocsMaxListCount]
+ }
+ return
}
func setRecentDocs(recentDocs []*RecentDoc) (err error) {