feat: support order by time asc

This commit is contained in:
Steven 2024-07-31 23:34:00 +08:00
parent ea70dd85bf
commit 07667257d5
5 changed files with 37 additions and 15 deletions

View File

@ -891,6 +891,9 @@ func (s *APIV1Service) buildMemoFindWithFilter(ctx context.Context, find *store.
if filter.OrderByPinned { if filter.OrderByPinned {
find.OrderByPinned = filter.OrderByPinned find.OrderByPinned = filter.OrderByPinned
} }
if filter.OrderByTimeAsc {
find.OrderByTimeAsc = filter.OrderByTimeAsc
}
if filter.DisplayTimeAfter != nil { if filter.DisplayTimeAfter != nil {
workspaceMemoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx) workspaceMemoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx)
if err != nil { if err != nil {
@ -995,6 +998,7 @@ var MemoFilterCELAttributes = []cel.EnvOption{
cel.Variable("visibilities", cel.ListType(cel.StringType)), cel.Variable("visibilities", cel.ListType(cel.StringType)),
cel.Variable("tag_search", cel.ListType(cel.StringType)), cel.Variable("tag_search", cel.ListType(cel.StringType)),
cel.Variable("order_by_pinned", cel.BoolType), cel.Variable("order_by_pinned", cel.BoolType),
cel.Variable("order_by_time_asc", cel.BoolType),
cel.Variable("display_time_before", cel.IntType), cel.Variable("display_time_before", cel.IntType),
cel.Variable("display_time_after", cel.IntType), cel.Variable("display_time_after", cel.IntType),
cel.Variable("creator", cel.StringType), cel.Variable("creator", cel.StringType),
@ -1014,6 +1018,7 @@ type MemoFilter struct {
Visibilities []store.Visibility Visibilities []store.Visibility
TagSearch []string TagSearch []string
OrderByPinned bool OrderByPinned bool
OrderByTimeAsc bool
DisplayTimeBefore *int64 DisplayTimeBefore *int64
DisplayTimeAfter *int64 DisplayTimeAfter *int64
Creator *string Creator *string
@ -1074,6 +1079,9 @@ func findMemoField(callExpr *expr.Expr_Call, filter *MemoFilter) {
} else if idExpr.Name == "order_by_pinned" { } else if idExpr.Name == "order_by_pinned" {
value := callExpr.Args[1].GetConstExpr().GetBoolValue() value := callExpr.Args[1].GetConstExpr().GetBoolValue()
filter.OrderByPinned = value filter.OrderByPinned = value
} else if idExpr.Name == "order_by_time_asc" {
value := callExpr.Args[1].GetConstExpr().GetBoolValue()
filter.OrderByTimeAsc = value
} else if idExpr.Name == "display_time_before" { } else if idExpr.Name == "display_time_before" {
displayTimeBefore := callExpr.Args[1].GetConstExpr().GetInt64Value() displayTimeBefore := callExpr.Args[1].GetConstExpr().GetInt64Value()
filter.DisplayTimeBefore = &displayTimeBefore filter.DisplayTimeBefore = &displayTimeBefore

View File

@ -116,12 +116,16 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if find.OrderByPinned { if find.OrderByPinned {
orders = append(orders, "`pinned` DESC") orders = append(orders, "`pinned` DESC")
} }
if find.OrderByUpdatedTs { order := "DESC"
orders = append(orders, "`updated_ts` DESC") if find.OrderByTimeAsc {
} else { order = "ASC"
orders = append(orders, "`created_ts` DESC")
} }
orders = append(orders, "`id` DESC") if find.OrderByUpdatedTs {
orders = append(orders, "`updated_ts` "+order)
} else {
orders = append(orders, "`created_ts` "+order)
}
orders = append(orders, "`id` "+order)
if find.Random { if find.Random {
orders = append(orders, "RAND()") orders = append(orders, "RAND()")
} }

View File

@ -107,12 +107,16 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if find.OrderByPinned { if find.OrderByPinned {
orders = append(orders, "pinned DESC") orders = append(orders, "pinned DESC")
} }
if find.OrderByUpdatedTs { order := "DESC"
orders = append(orders, "updated_ts DESC") if find.OrderByTimeAsc {
} else { order = "ASC"
orders = append(orders, "created_ts DESC")
} }
orders = append(orders, "id DESC") if find.OrderByUpdatedTs {
orders = append(orders, "updated_ts "+order)
} else {
orders = append(orders, "created_ts "+order)
}
orders = append(orders, "id "+order)
if find.Random { if find.Random {
orders = append(orders, "RAND()") orders = append(orders, "RAND()")
} }

View File

@ -108,12 +108,16 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
if find.OrderByPinned { if find.OrderByPinned {
orderBy = append(orderBy, "`pinned` DESC") orderBy = append(orderBy, "`pinned` DESC")
} }
if find.OrderByUpdatedTs { order := "DESC"
orderBy = append(orderBy, "`updated_ts` DESC") if find.OrderByTimeAsc {
} else { order = "ASC"
orderBy = append(orderBy, "`created_ts` DESC")
} }
orderBy = append(orderBy, "`id` DESC") if find.OrderByUpdatedTs {
orderBy = append(orderBy, "`updated_ts` "+order)
} else {
orderBy = append(orderBy, "`created_ts` "+order)
}
orderBy = append(orderBy, "`id` "+order)
if find.Random { if find.Random {
orderBy = []string{"RANDOM()"} orderBy = []string{"RANDOM()"}
} }

View File

@ -80,6 +80,8 @@ type FindMemo struct {
Offset *int Offset *int
OrderByUpdatedTs bool OrderByUpdatedTs bool
OrderByPinned bool OrderByPinned bool
OrderByTimeAsc bool
} }
type FindMemoPayload struct { type FindMemoPayload struct {