Skip to content

Commit 6e41587

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents fdef739 + ca3dd41 commit 6e41587

File tree

5 files changed

+42
-62
lines changed

5 files changed

+42
-62
lines changed

app/changelogs/v3.3.6/v3.3.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Below are the detailed changes in this version.
1111
* [Support `siyuan://` protocol on macOS](https://github.com/siyuan-note/siyuan/issues/12271)
1212
* [Improve UI layout](https://github.com/siyuan-note/siyuan/pull/15011)
1313
* [Improve the outline panel](https://github.com/siyuan-note/siyuan/pull/15814)
14+
* [Improve `Recent documents`](https://github.com/siyuan-note/siyuan/pull/15824)
1415
* [Improve code block language selection](https://github.com/siyuan-note/siyuan/pull/15966)
1516
* [Improve the database history](https://github.com/siyuan-note/siyuan/issues/16092)
1617
* [Improve the prompt displayed when the web page does not have permission to read the clipboard](https://github.com/siyuan-note/siyuan/issues/16100)

app/changelogs/v3.3.6/v3.3.6_zh_CHT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [在 macOS 上支援 `siyuan://` 協定](https://github.com/siyuan-note/siyuan/issues/12271)
1212
* [改進介面佈局](https://github.com/siyuan-note/siyuan/pull/15011)
1313
* [改進大綱面板](https://github.com/siyuan-note/siyuan/pull/15814)
14+
* [改進 `最近的文件`](https://github.com/siyuan-note/siyuan/pull/15824)
1415
* [改進程式碼區塊語言選擇](https://github.com/siyuan-note/siyuan/pull/15966)
1516
* [改進資料庫歷史](https://github.com/siyuan-note/siyuan/issues/16092)
1617
* [改進網頁無權限讀取剪貼簿時顯示的提示](https://github.com/siyuan-note/siyuan/issues/16100)

app/changelogs/v3.3.6/v3.3.6_zh_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [在 macOS 上支持 `siyuan://` 协议](https://github.com/siyuan-note/siyuan/issues/12271)
1212
* [改进界面布局](https://github.com/siyuan-note/siyuan/pull/15011)
1313
* [改进大纲面板](https://github.com/siyuan-note/siyuan/pull/15814)
14+
* [改进 `最近的文档`](https://github.com/siyuan-note/siyuan/pull/15824)
1415
* [改进代码块语言选择](https://github.com/siyuan-note/siyuan/pull/15966)
1516
* [改进数据库历史](https://github.com/siyuan-note/siyuan/issues/16092)
1617
* [改进网页无权限读取剪贴板时显示的提示](https://github.com/siyuan-note/siyuan/issues/16100)

kernel/api/storage.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func getRecentDocs(c *gin.Context) {
3535
}
3636

3737
// 获取排序参数
38-
sortBy := "viewedAt" // 默认按浏览时间排序
38+
sortBy := "viewedAt" // 默认按浏览时间排序,openAt:按打开时间排序,closedAt:按关闭时间排序
3939
if arg["sortBy"] != nil {
4040
sortBy = arg["sortBy"].(string)
4141
}
@@ -248,7 +248,6 @@ func removeOutlineStorage(c *gin.Context) {
248248
}
249249
}
250250

251-
252251
func updateRecentDocViewTime(c *gin.Context) {
253252
ret := gulu.Ret.NewResult()
254253
defer c.JSON(http.StatusOK, ret)
@@ -267,7 +266,6 @@ func updateRecentDocViewTime(c *gin.Context) {
267266
}
268267
}
269268

270-
271269
func updateRecentDocOpenTime(c *gin.Context) {
272270
ret := gulu.Ret.NewResult()
273271
defer c.JSON(http.StatusOK, ret)
@@ -302,4 +300,4 @@ func updateRecentDocCloseTime(c *gin.Context) {
302300
ret.Msg = err.Error()
303301
return
304302
}
305-
}
303+
}

kernel/model/storage.go

Lines changed: 37 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func RemoveRecentDoc(ids []string) {
5353
recentDocLock.Lock()
5454
defer recentDocLock.Unlock()
5555

56-
recentDocs, err := getRecentDocs()
56+
recentDocs, err := getRecentDocs("")
5757
if err != nil {
5858
return
5959
}
@@ -86,7 +86,7 @@ func setRecentDocByTree(tree *parse.Tree) {
8686
recentDocLock.Lock()
8787
defer recentDocLock.Unlock()
8888

89-
recentDocs, err := getRecentDocs()
89+
recentDocs, err := getRecentDocs("")
9090
if err != nil {
9191
return
9292
}
@@ -112,7 +112,7 @@ func UpdateRecentDocOpenTime(rootID string) (err error) {
112112
recentDocLock.Lock()
113113
defer recentDocLock.Unlock()
114114

115-
recentDocs, err := getRecentDocs()
115+
recentDocs, err := getRecentDocs("")
116116
if err != nil {
117117
return
118118
}
@@ -138,7 +138,7 @@ func UpdateRecentDocViewTime(rootID string) (err error) {
138138
recentDocLock.Lock()
139139
defer recentDocLock.Unlock()
140140

141-
recentDocs, err := getRecentDocs()
141+
recentDocs, err := getRecentDocs("")
142142
if err != nil {
143143
return
144144
}
@@ -168,7 +168,7 @@ func UpdateRecentDocCloseTime(rootID string) (err error) {
168168
recentDocLock.Lock()
169169
defer recentDocLock.Unlock()
170170

171-
recentDocs, err := getRecentDocs()
171+
recentDocs, err := getRecentDocs("")
172172
if err != nil {
173173
return
174174
}
@@ -189,10 +189,10 @@ func UpdateRecentDocCloseTime(rootID string) (err error) {
189189
return
190190
}
191191

192-
func GetRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) {
192+
func GetRecentDocs(sortBy string) (ret []*RecentDoc, err error) {
193193
recentDocLock.Lock()
194194
defer recentDocLock.Unlock()
195-
return getRecentDocs(sortBy...)
195+
return getRecentDocs(sortBy)
196196
}
197197

198198
func setRecentDocs(recentDocs []*RecentDoc) (err error) {
@@ -217,7 +217,7 @@ func setRecentDocs(recentDocs []*RecentDoc) (err error) {
217217
return
218218
}
219219

220-
func getRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) {
220+
func getRecentDocs(sortBy string) (ret []*RecentDoc, err error) {
221221
tmp := []*RecentDoc{}
222222
dataPath := filepath.Join(util.DataDir, "storage/recent-doc.json")
223223
if !filelock.IsExist(dataPath) {
@@ -255,56 +255,36 @@ func getRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) {
255255
}
256256

257257
// 根据排序参数进行排序
258-
if len(sortBy) > 0 {
259-
switch sortBy[0] {
260-
case "closedAt":
261-
// 按关闭时间排序
262-
sort.Slice(ret, func(i, j int) bool {
263-
if ret[i].ClosedAt == 0 && ret[j].ClosedAt == 0 {
264-
// 如果都没有关闭时间,按浏览时间排序
265-
return ret[i].ViewedAt > ret[j].ViewedAt
266-
}
267-
if ret[i].ClosedAt == 0 {
268-
return false // 没有关闭时间的排在后面
269-
}
270-
if ret[j].ClosedAt == 0 {
271-
return true // 有关闭时间的排在前面
272-
}
273-
return ret[i].ClosedAt > ret[j].ClosedAt
274-
})
275-
case "openAt":
276-
// 按打开时间排序
277-
sort.Slice(ret, func(i, j int) bool {
278-
if ret[i].OpenAt == 0 && ret[j].OpenAt == 0 {
279-
// 如果都没有打开时间,按ID时间排序(ID包含时间信息)
280-
return ret[i].RootID > ret[j].RootID
281-
}
282-
if ret[i].OpenAt == 0 {
283-
return false // 没有打开时间的排在后面
284-
}
285-
if ret[j].OpenAt == 0 {
286-
return true // 有打开时间的排在前面
287-
}
288-
return ret[i].OpenAt > ret[j].OpenAt
289-
})
290-
default:
291-
// 默认按浏览时间排序
292-
sort.Slice(ret, func(i, j int) bool {
293-
if ret[i].ViewedAt == 0 && ret[j].ViewedAt == 0 {
294-
// 如果都没有浏览时间,按ID时间排序(ID包含时间信息)
295-
return ret[i].RootID > ret[j].RootID
296-
}
297-
if ret[i].ViewedAt == 0 {
298-
return false // 没有浏览时间的排在后面
299-
}
300-
if ret[j].ViewedAt == 0 {
301-
return true // 有浏览时间的排在前面
302-
}
258+
switch sortBy {
259+
case "closedAt": // 按关闭时间排序
260+
sort.Slice(ret, func(i, j int) bool {
261+
if ret[i].ClosedAt == 0 && ret[j].ClosedAt == 0 {
262+
// 如果都没有关闭时间,按浏览时间排序
303263
return ret[i].ViewedAt > ret[j].ViewedAt
304-
})
305-
}
306-
} else {
307-
// 默认按浏览时间降序排序,如果ViewedAt为0则使用文档创建时间
264+
}
265+
if ret[i].ClosedAt == 0 {
266+
return false // 没有关闭时间的排在后面
267+
}
268+
if ret[j].ClosedAt == 0 {
269+
return true // 有关闭时间的排在前面
270+
}
271+
return ret[i].ClosedAt > ret[j].ClosedAt
272+
})
273+
case "openAt": // 按打开时间排序
274+
sort.Slice(ret, func(i, j int) bool {
275+
if ret[i].OpenAt == 0 && ret[j].OpenAt == 0 {
276+
// 如果都没有打开时间,按ID时间排序(ID包含时间信息)
277+
return ret[i].RootID > ret[j].RootID
278+
}
279+
if ret[i].OpenAt == 0 {
280+
return false // 没有打开时间的排在后面
281+
}
282+
if ret[j].OpenAt == 0 {
283+
return true // 有打开时间的排在前面
284+
}
285+
return ret[i].OpenAt > ret[j].OpenAt
286+
})
287+
default: // 默认按浏览时间排序
308288
sort.Slice(ret, func(i, j int) bool {
309289
if ret[i].ViewedAt == 0 && ret[j].ViewedAt == 0 {
310290
// 如果都没有浏览时间,按ID时间排序(ID包含时间信息)
@@ -319,7 +299,6 @@ func getRecentDocs(sortBy ...string) (ret []*RecentDoc, err error) {
319299
return ret[i].ViewedAt > ret[j].ViewedAt
320300
})
321301
}
322-
323302
return
324303
}
325304

0 commit comments

Comments
 (0)