返回 DeepSeek-Reasonix
topic_sort.go
根目录 / internal / sessioncatalog / topic_sort.go
1 package sessioncatalog
2
3 import (
4 "errors"
5 "strings"
6 )
7
8 const unrankedTopicSortOrder int64 = 1<<63 - 1
9
10 var errCursorSortModeChanged = errors.New("session catalog cursor sort mode changed")
11
12 func topicPageSortExpression(sortMode string) string {
13 if strings.TrimSpace(sortMode) == "created" {
14 return "COALESCE(NULLIF(created_at,0),last_activity_at,0)"
15 }
16 return "COALESCE(NULLIF(last_activity_at,0),created_at,0)"
17 }
18
19 func topicPageSortValue(topic TopicRecord, sortMode string) int64 {
20 if strings.TrimSpace(sortMode) == "created" {
21 if topic.CreatedAt > 0 {
22 return topic.CreatedAt
23 }
24 return topic.LastActivityAt
25 }
26 if topic.LastActivityAt > 0 {
27 return topic.LastActivityAt
28 }
29 return topic.CreatedAt
30 }
31
32 func topicPageManualSortValue(topic TopicRecord) int64 {
33 if topic.SortOrder < 0 {
34 return unrankedTopicSortOrder
35 }
36 return int64(topic.SortOrder)
37 }
38
39 func topicPageManualSortExpression() string {
40 return "CASE WHEN metadata_present=1 AND sort_order>=0 THEN sort_order ELSE 9223372036854775807 END"
41 }
42
42 lines GO