mirror of
https://github.com/usememos/memos.git
synced 2025-02-16 03:12:13 +01:00
chore: fix memo resources position
This commit is contained in:
parent
501f8898f6
commit
8b9455d784
@ -2,6 +2,8 @@ package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@ -11,7 +13,9 @@ import (
|
||||
)
|
||||
|
||||
func (s *APIV2Service) SetMemoResources(ctx context.Context, request *apiv2pb.SetMemoResourcesRequest) (*apiv2pb.SetMemoResourcesResponse, error) {
|
||||
resources, err := s.Store.ListResources(ctx, &store.FindResource{MemoID: &request.Id})
|
||||
resources, err := s.Store.ListResources(ctx, &store.FindResource{
|
||||
MemoID: &request.Id,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to list resources")
|
||||
}
|
||||
@ -35,11 +39,14 @@ func (s *APIV2Service) SetMemoResources(ctx context.Context, request *apiv2pb.Se
|
||||
}
|
||||
}
|
||||
|
||||
slices.Reverse(request.Resources)
|
||||
// Update resources' memo_id in the request.
|
||||
for _, resource := range request.Resources {
|
||||
for index, resource := range request.Resources {
|
||||
updatedTs := time.Now().Unix() + int64(index)
|
||||
if _, err := s.Store.UpdateResource(ctx, &store.UpdateResource{
|
||||
ID: resource.Id,
|
||||
MemoID: &request.Id,
|
||||
ID: resource.Id,
|
||||
MemoID: &request.Id,
|
||||
UpdatedTs: &updatedTs,
|
||||
}); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to update resource")
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
|
||||
fields = append(fields, "`blob`")
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("SELECT %s FROM `resource` WHERE %s GROUP BY `id` ORDER BY `created_ts` DESC", strings.Join(fields, ", "), strings.Join(where, " AND "))
|
||||
query := fmt.Sprintf("SELECT %s FROM `resource` WHERE %s ORDER BY `updated_ts` DESC, `created_ts` DESC", strings.Join(fields, ", "), strings.Join(where, " AND "))
|
||||
if find.Limit != nil {
|
||||
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
|
||||
if find.Offset != nil {
|
||||
|
@ -49,8 +49,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
|
||||
%s
|
||||
FROM resource
|
||||
WHERE %s
|
||||
GROUP BY id
|
||||
ORDER BY created_ts DESC
|
||||
ORDER BY updated_ts DESC, created_ts DESC
|
||||
`, strings.Join(fields, ", "), strings.Join(where, " AND "))
|
||||
if find.Limit != nil {
|
||||
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
|
||||
|
@ -51,8 +51,7 @@ func (d *DB) ListResources(ctx context.Context, find *store.FindResource) ([]*st
|
||||
%s
|
||||
FROM resource
|
||||
WHERE %s
|
||||
GROUP BY id
|
||||
ORDER BY created_ts DESC
|
||||
ORDER BY updated_ts DESC, created_ts DESC
|
||||
`, strings.Join(fields, ", "), strings.Join(where, " AND "))
|
||||
if find.Limit != nil {
|
||||
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
|
||||
|
Loading…
x
Reference in New Issue
Block a user