From 8e0ce4d67835db1833eeb5e6b8e736a8e13605c8 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 14 Jan 2024 20:51:52 +0800 Subject: [PATCH] fix: list memos with pinned --- api/v2/memo_service.go | 2 ++ store/db/mysql/memo.go | 8 ++------ store/db/postgres/memo.go | 8 ++------ store/db/sqlite/memo.go | 8 ++------ web/src/pages/Explore.tsx | 2 +- web/src/pages/Home.tsx | 2 +- 6 files changed, 10 insertions(+), 20 deletions(-) diff --git a/api/v2/memo_service.go b/api/v2/memo_service.go index 555e38ad..9aad1f36 100644 --- a/api/v2/memo_service.go +++ b/api/v2/memo_service.go @@ -130,6 +130,8 @@ func (s *APIV2Service) ListMemos(ctx context.Context, request *apiv2pb.ListMemos if filter.RowStatus != nil { memoFind.RowStatus = filter.RowStatus } + } else { + return nil, status.Errorf(codes.InvalidArgument, "filter is required") } user, _ := getCurrentUser(ctx, s.Store) diff --git a/store/db/mysql/memo.go b/store/db/mysql/memo.go index c9d66a37..d43c9076 100644 --- a/store/db/mysql/memo.go +++ b/store/db/mysql/memo.go @@ -90,7 +90,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo "UNIX_TIMESTAMP(`memo`.`updated_ts`) AS `updated_ts`", "`memo`.`row_status` AS `row_status`", "`memo`.`visibility` AS `visibility`", - "`memo_organizer`.`pinned` AS `pinned`", + "IFNULL(`memo_organizer`.`pinned`, 0) AS `pinned`", "`memo_relation`.`related_memo_id` AS `parent_id`", } if !find.ExcludeContent { @@ -114,7 +114,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo list := make([]*store.Memo, 0) for rows.Next() { var memo store.Memo - pinned := sql.NullBool{} dests := []any{ &memo.ID, &memo.CreatorID, @@ -122,7 +121,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo &memo.UpdatedTs, &memo.RowStatus, &memo.Visibility, - &pinned, + &memo.Pinned, &memo.ParentID, } if !find.ExcludeContent { @@ -131,9 +130,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo if err := rows.Scan(dests...); err != nil { return nil, err } - if pinned.Valid { - memo.Pinned = pinned.Bool - } list = append(list, &memo) } diff --git a/store/db/postgres/memo.go b/store/db/postgres/memo.go index 52f4c7e1..bb9e9390 100644 --- a/store/db/postgres/memo.go +++ b/store/db/postgres/memo.go @@ -81,7 +81,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo `memo.updated_ts AS updated_ts`, `memo.row_status AS row_status`, `memo.visibility AS visibility`, - `memo_organizer.pinned AS pinned`, + `COALESCE(memo_organizer.pinned, 0) AS pinned`, `memo_relation.related_memo_id AS parent_id`, } if !find.ExcludeContent { @@ -110,7 +110,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo list := make([]*store.Memo, 0) for rows.Next() { var memo store.Memo - pinned := sql.NullBool{} dests := []any{ &memo.ID, &memo.CreatorID, @@ -118,7 +117,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo &memo.UpdatedTs, &memo.RowStatus, &memo.Visibility, - &pinned, + &memo.Pinned, &memo.ParentID, } if !find.ExcludeContent { @@ -127,9 +126,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo if err := rows.Scan(dests...); err != nil { return nil, err } - if pinned.Valid { - memo.Pinned = pinned.Bool - } list = append(list, &memo) } diff --git a/store/db/sqlite/memo.go b/store/db/sqlite/memo.go index 43e347bc..f39f6f17 100644 --- a/store/db/sqlite/memo.go +++ b/store/db/sqlite/memo.go @@ -80,7 +80,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo `memo.updated_ts AS updated_ts`, `memo.row_status AS row_status`, `memo.visibility AS visibility`, - `memo_organizer.pinned AS pinned`, + `IFNULL(memo_organizer.pinned, 0) AS pinned`, `memo_relation.related_memo_id AS parent_id`, } if !find.ExcludeContent { @@ -109,7 +109,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo list := make([]*store.Memo, 0) for rows.Next() { var memo store.Memo - pinned := sql.NullBool{} dests := []any{ &memo.ID, &memo.CreatorID, @@ -117,7 +116,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo &memo.UpdatedTs, &memo.RowStatus, &memo.Visibility, - &pinned, + &memo.Pinned, &memo.ParentID, } if !find.ExcludeContent { @@ -126,9 +125,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo if err := rows.Scan(dests...); err != nil { return nil, err } - if pinned.Valid { - memo.Pinned = pinned.Bool - } list = append(list, &memo) } diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsx index c7dd356e..4b37bc36 100644 --- a/web/src/pages/Explore.tsx +++ b/web/src/pages/Explore.tsx @@ -42,9 +42,9 @@ const Explore = () => { } setIsRequesting(true); const data = await memoStore.fetchMemos({ + filter: filters.join(" && "), limit: DEFAULT_MEMO_LIMIT, offset: memoList.size(), - filter: filters.join(" && "), }); setIsRequesting(false); setIsComplete(data.length < DEFAULT_MEMO_LIMIT); diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index c9c10dca..6397dae7 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -52,9 +52,9 @@ const Home = () => { } setIsRequesting(true); const data = await memoStore.fetchMemos({ + filter: filters.join(" && "), limit: DEFAULT_MEMO_LIMIT, offset: memoList.size(), - filter: filters.join(" && "), }); setIsRequesting(false); setIsComplete(data.length < DEFAULT_MEMO_LIMIT);