@@ -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
198198func 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