Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Supports configuring the maximum number of `Recent documents` to be listed https://github.com/siyuan-note/siyuan/issues/16720

Daniel96c2093bd8c6
diff --git a/app/src/mobile/settings/fileTree.ts b/app/src/mobile/settings/fileTree.ts
index f73fbaba7e..2c24ec6a4d 100644
--- a/app/src/mobile/settings/fileTree.ts
+++ b/app/src/mobile/settings/fileTree.ts
@@ -54,6 +54,12 @@ export const initFileTree = () => {
<input class="b3-text-field fn__block" id="maxListCount" type="number" min="1" max="10240" value="${window.siyuan.config.fileTree.maxListCount}">
<div class="b3-label__text">${window.siyuan.languages.fileTree17}</div>
</div>
+<div class="b3-label">
+ ${window.siyuan.languages.recentDocsMaxCount}
+ <span class="fn__hr"></span>
+ <input class="b3-text-field fn__block" id="recentDocsMaxListCount" type="number" min="1" max="256" value="${window.siyuan.config.fileTree.recentDocsMaxListCount}">
+ <div class="b3-label__text">${window.siyuan.languages.recentDocsMaxCountTip}</div>
+</div>
<div class="b3-label">
${window.siyuan.languages.fileTree12}
<span class="fn__hr"></span>
@@ -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 dea84ec126..0362a1fbdf 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 62add8ed98..31f7e430fb 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 6d69ebe82f..96ddc99f1c 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 604884c053..21e1e345dc 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) {