From 994bdc06a2ed5dc48d4c8d9ae424ae21ecb3699a Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 24 Oct 2025 11:41:18 +0800 Subject: [PATCH 1/2] :art: Improve `Recent documents` https://github.com/siyuan-note/siyuan/pull/15824 Signed-off-by: Daniel <845765@qq.com> --- kernel/api/storage.go | 6 +-- kernel/model/storage.go | 95 ++++++++++++++++------------------------- 2 files changed, 39 insertions(+), 62 deletions(-) diff --git a/kernel/api/storage.go b/kernel/api/storage.go index 034f56a7c..c94b0f3c9 100644 --- a/kernel/api/storage.go +++ b/kernel/api/storage.go @@ -35,7 +35,7 @@ func getRecentDocs(c *gin.Context) { } // 获取排序参数 - sortBy := "viewedAt" // 默认按浏览时间排序 + sortBy := "viewedAt" // 默认按浏览时间排序,openAt:按打开时间排序,closedAt:按关闭时间排序 if arg["sortBy"] != nil { sortBy = arg["sortBy"].(string) } @@ -248,7 +248,6 @@ func removeOutlineStorage(c *gin.Context) { } } - func updateRecentDocViewTime(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) @@ -267,7 +266,6 @@ func updateRecentDocViewTime(c *gin.Context) { } } - func updateRecentDocOpenTime(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) @@ -302,4 +300,4 @@ func updateRecentDocCloseTime(c *gin.Context) { ret.Msg = err.Error() return } -} \ No newline at end of file +} diff --git a/kernel/model/storage.go b/kernel/model/storage.go index 0731e7592..7f506ac43 100644 --- a/kernel/model/storage.go +++ b/kernel/model/storage.go @@ -53,7 +53,7 @@ func RemoveRecentDoc(ids []string) { recentDocLock.Lock() defer recentDocLock.Unlock() - recentDocs, err := getRecentDocs() + recentDocs, err := getRecentDocs("") if err != nil { return } @@ -86,7 +86,7 @@ func setRecentDocByTree(tree *parse.Tree) { recentDocLock.Lock() defer recentDocLock.Unlock() - recentDocs, err := getRecentDocs() + recentDocs, err := getRecentDocs("") if err != nil { return } @@ -112,7 +112,7 @@ func UpdateRecentDocOpenTime(rootID string) (err error) { recentDocLock.Lock() defer recentDocLock.Unlock() - recentDocs, err := getRecentDocs() + recentDocs, err := getRecentDocs("") if err != nil { return } @@ -138,7 +138,7 @@ func UpdateRecentDocViewTime(rootID string) (err error) { recentDocLock.Lock() defer recentDocLock.Unlock() - recentDocs, err := getRecentDocs() + recentDocs, err := getRecentDocs("") if err != nil { return } @@ -168,7 +168,7 @@ func UpdateRecentDocCloseTime(rootID string) (err error) { recentDocLock.Lock() defer recentDocLock.Unlock() - recentDocs, err := getRecentDocs() + recentDocs, err := getRecentDocs("") if err != nil { return } @@ -189,10 +189,10 @@ func UpdateRecentDocCloseTime(rootID string) (err error) { return } -func GetRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) { +func GetRecentDocs(sortBy string) (ret []*RecentDoc, err error) { recentDocLock.Lock() defer recentDocLock.Unlock() - return getRecentDocs(sortBy...) + return getRecentDocs(sortBy) } func setRecentDocs(recentDocs []*RecentDoc) (err error) { @@ -217,7 +217,7 @@ func setRecentDocs(recentDocs []*RecentDoc) (err error) { return } -func getRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) { +func getRecentDocs(sortBy string) (ret []*RecentDoc, err error) { tmp := []*RecentDoc{} dataPath := filepath.Join(util.DataDir, "storage/recent-doc.json") if !filelock.IsExist(dataPath) { @@ -255,56 +255,36 @@ func getRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) { } // 根据排序参数进行排序 - if len(sortBy) > 0 { - switch sortBy[0] { - case "closedAt": - // 按关闭时间排序 - sort.Slice(ret, func(i, j int) bool { - if ret[i].ClosedAt == 0 && ret[j].ClosedAt == 0 { - // 如果都没有关闭时间,按浏览时间排序 - return ret[i].ViewedAt > ret[j].ViewedAt - } - if ret[i].ClosedAt == 0 { - return false // 没有关闭时间的排在后面 - } - if ret[j].ClosedAt == 0 { - return true // 有关闭时间的排在前面 - } - return ret[i].ClosedAt > ret[j].ClosedAt - }) - case "openAt": - // 按打开时间排序 - sort.Slice(ret, func(i, j int) bool { - if ret[i].OpenAt == 0 && ret[j].OpenAt == 0 { - // 如果都没有打开时间,按ID时间排序(ID包含时间信息) - return ret[i].RootID > ret[j].RootID - } - if ret[i].OpenAt == 0 { - return false // 没有打开时间的排在后面 - } - if ret[j].OpenAt == 0 { - return true // 有打开时间的排在前面 - } - return ret[i].OpenAt > ret[j].OpenAt - }) - default: - // 默认按浏览时间排序 - sort.Slice(ret, func(i, j int) bool { - if ret[i].ViewedAt == 0 && ret[j].ViewedAt == 0 { - // 如果都没有浏览时间,按ID时间排序(ID包含时间信息) - return ret[i].RootID > ret[j].RootID - } - if ret[i].ViewedAt == 0 { - return false // 没有浏览时间的排在后面 - } - if ret[j].ViewedAt == 0 { - return true // 有浏览时间的排在前面 - } + switch sortBy { + case "closedAt": // 按关闭时间排序 + sort.Slice(ret, func(i, j int) bool { + if ret[i].ClosedAt == 0 && ret[j].ClosedAt == 0 { + // 如果都没有关闭时间,按浏览时间排序 return ret[i].ViewedAt > ret[j].ViewedAt - }) - } - } else { - // 默认按浏览时间降序排序,如果ViewedAt为0则使用文档创建时间 + } + if ret[i].ClosedAt == 0 { + return false // 没有关闭时间的排在后面 + } + if ret[j].ClosedAt == 0 { + return true // 有关闭时间的排在前面 + } + return ret[i].ClosedAt > ret[j].ClosedAt + }) + case "openAt": // 按打开时间排序 + sort.Slice(ret, func(i, j int) bool { + if ret[i].OpenAt == 0 && ret[j].OpenAt == 0 { + // 如果都没有打开时间,按ID时间排序(ID包含时间信息) + return ret[i].RootID > ret[j].RootID + } + if ret[i].OpenAt == 0 { + return false // 没有打开时间的排在后面 + } + if ret[j].OpenAt == 0 { + return true // 有打开时间的排在前面 + } + return ret[i].OpenAt > ret[j].OpenAt + }) + default: // 默认按浏览时间排序 sort.Slice(ret, func(i, j int) bool { if ret[i].ViewedAt == 0 && ret[j].ViewedAt == 0 { // 如果都没有浏览时间,按ID时间排序(ID包含时间信息) @@ -319,7 +299,6 @@ func getRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) { return ret[i].ViewedAt > ret[j].ViewedAt }) } - return } From ca3dd41fa0333decad56342395f82db492bb4c86 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 24 Oct 2025 12:25:34 +0800 Subject: [PATCH 2/2] :memo: Update changelogs Signed-off-by: Daniel <845765@qq.com> --- app/changelogs/v3.3.6/v3.3.6.md | 1 + app/changelogs/v3.3.6/v3.3.6_zh_CHT.md | 1 + app/changelogs/v3.3.6/v3.3.6_zh_CN.md | 1 + 3 files changed, 3 insertions(+) diff --git a/app/changelogs/v3.3.6/v3.3.6.md b/app/changelogs/v3.3.6/v3.3.6.md index 08169dbe7..7d69b9ba9 100644 --- a/app/changelogs/v3.3.6/v3.3.6.md +++ b/app/changelogs/v3.3.6/v3.3.6.md @@ -11,6 +11,7 @@ Below are the detailed changes in this version. * [Support `siyuan://` protocol on macOS](https://github.com/siyuan-note/siyuan/issues/12271) * [Improve UI layout](https://github.com/siyuan-note/siyuan/pull/15011) * [Improve the outline panel](https://github.com/siyuan-note/siyuan/pull/15814) +* [Improve `Recent documents`](https://github.com/siyuan-note/siyuan/pull/15824) * [Improve code block language selection](https://github.com/siyuan-note/siyuan/pull/15966) * [Improve the database history](https://github.com/siyuan-note/siyuan/issues/16092) * [Improve the prompt displayed when the web page does not have permission to read the clipboard](https://github.com/siyuan-note/siyuan/issues/16100) diff --git a/app/changelogs/v3.3.6/v3.3.6_zh_CHT.md b/app/changelogs/v3.3.6/v3.3.6_zh_CHT.md index 632a67e70..56193656f 100644 --- a/app/changelogs/v3.3.6/v3.3.6_zh_CHT.md +++ b/app/changelogs/v3.3.6/v3.3.6_zh_CHT.md @@ -11,6 +11,7 @@ * [在 macOS 上支援 `siyuan://` 協定](https://github.com/siyuan-note/siyuan/issues/12271) * [改進介面佈局](https://github.com/siyuan-note/siyuan/pull/15011) * [改進大綱面板](https://github.com/siyuan-note/siyuan/pull/15814) +* [改進 `最近的文件`](https://github.com/siyuan-note/siyuan/pull/15824) * [改進程式碼區塊語言選擇](https://github.com/siyuan-note/siyuan/pull/15966) * [改進資料庫歷史](https://github.com/siyuan-note/siyuan/issues/16092) * [改進網頁無權限讀取剪貼簿時顯示的提示](https://github.com/siyuan-note/siyuan/issues/16100) diff --git a/app/changelogs/v3.3.6/v3.3.6_zh_CN.md b/app/changelogs/v3.3.6/v3.3.6_zh_CN.md index 1c5dc9419..e269131f7 100644 --- a/app/changelogs/v3.3.6/v3.3.6_zh_CN.md +++ b/app/changelogs/v3.3.6/v3.3.6_zh_CN.md @@ -11,6 +11,7 @@ * [在 macOS 上支持 `siyuan://` 协议](https://github.com/siyuan-note/siyuan/issues/12271) * [改进界面布局](https://github.com/siyuan-note/siyuan/pull/15011) * [改进大纲面板](https://github.com/siyuan-note/siyuan/pull/15814) +* [改进 `最近的文档`](https://github.com/siyuan-note/siyuan/pull/15824) * [改进代码块语言选择](https://github.com/siyuan-note/siyuan/pull/15966) * [改进数据库历史](https://github.com/siyuan-note/siyuan/issues/16092) * [改进网页无权限读取剪贴板时显示的提示](https://github.com/siyuan-note/siyuan/issues/16100)