mirror of
https://github.com/usememos/memos.git
synced 2025-03-18 11:40:09 +01:00
feat: support order by time asc
This commit is contained in:
parent
ea70dd85bf
commit
07667257d5
@ -891,6 +891,9 @@ func (s *APIV1Service) buildMemoFindWithFilter(ctx context.Context, find *store.
|
||||
if filter.OrderByPinned {
|
||||
find.OrderByPinned = filter.OrderByPinned
|
||||
}
|
||||
if filter.OrderByTimeAsc {
|
||||
find.OrderByTimeAsc = filter.OrderByTimeAsc
|
||||
}
|
||||
if filter.DisplayTimeAfter != nil {
|
||||
workspaceMemoRelatedSetting, err := s.Store.GetWorkspaceMemoRelatedSetting(ctx)
|
||||
if err != nil {
|
||||
@ -995,6 +998,7 @@ var MemoFilterCELAttributes = []cel.EnvOption{
|
||||
cel.Variable("visibilities", cel.ListType(cel.StringType)),
|
||||
cel.Variable("tag_search", cel.ListType(cel.StringType)),
|
||||
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_after", cel.IntType),
|
||||
cel.Variable("creator", cel.StringType),
|
||||
@ -1014,6 +1018,7 @@ type MemoFilter struct {
|
||||
Visibilities []store.Visibility
|
||||
TagSearch []string
|
||||
OrderByPinned bool
|
||||
OrderByTimeAsc bool
|
||||
DisplayTimeBefore *int64
|
||||
DisplayTimeAfter *int64
|
||||
Creator *string
|
||||
@ -1074,6 +1079,9 @@ func findMemoField(callExpr *expr.Expr_Call, filter *MemoFilter) {
|
||||
} else if idExpr.Name == "order_by_pinned" {
|
||||
value := callExpr.Args[1].GetConstExpr().GetBoolValue()
|
||||
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" {
|
||||
displayTimeBefore := callExpr.Args[1].GetConstExpr().GetInt64Value()
|
||||
filter.DisplayTimeBefore = &displayTimeBefore
|
||||
|
@ -116,12 +116,16 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
if find.OrderByPinned {
|
||||
orders = append(orders, "`pinned` DESC")
|
||||
}
|
||||
if find.OrderByUpdatedTs {
|
||||
orders = append(orders, "`updated_ts` DESC")
|
||||
} else {
|
||||
orders = append(orders, "`created_ts` DESC")
|
||||
order := "DESC"
|
||||
if find.OrderByTimeAsc {
|
||||
order = "ASC"
|
||||
}
|
||||
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 {
|
||||
orders = append(orders, "RAND()")
|
||||
}
|
||||
|
@ -107,12 +107,16 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
if find.OrderByPinned {
|
||||
orders = append(orders, "pinned DESC")
|
||||
}
|
||||
if find.OrderByUpdatedTs {
|
||||
orders = append(orders, "updated_ts DESC")
|
||||
} else {
|
||||
orders = append(orders, "created_ts DESC")
|
||||
order := "DESC"
|
||||
if find.OrderByTimeAsc {
|
||||
order = "ASC"
|
||||
}
|
||||
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 {
|
||||
orders = append(orders, "RAND()")
|
||||
}
|
||||
|
@ -108,12 +108,16 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
||||
if find.OrderByPinned {
|
||||
orderBy = append(orderBy, "`pinned` DESC")
|
||||
}
|
||||
if find.OrderByUpdatedTs {
|
||||
orderBy = append(orderBy, "`updated_ts` DESC")
|
||||
} else {
|
||||
orderBy = append(orderBy, "`created_ts` DESC")
|
||||
order := "DESC"
|
||||
if find.OrderByTimeAsc {
|
||||
order = "ASC"
|
||||
}
|
||||
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 {
|
||||
orderBy = []string{"RANDOM()"}
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ type FindMemo struct {
|
||||
Offset *int
|
||||
OrderByUpdatedTs bool
|
||||
OrderByPinned bool
|
||||
|
||||
OrderByTimeAsc bool
|
||||
}
|
||||
|
||||
type FindMemoPayload struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user