Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: update find memo api

Steven6f2ca6c87ad2
diff --git a/api/v1/memo.go b/api/v1/memo.go
index 5c402991d..9a0eb1f25 100644
--- a/api/v1/memo.go
+++ b/api/v1/memo.go
@@ -471,8 +471,9 @@ func (s *APIV1Service) GetMemoStats(c echo.Context) error {
normalStatus := store.Normal
hasParentFlag := false
findMemoMessage := &store.FindMemo{
- RowStatus: &normalStatus,
- HasParent: &hasParentFlag,
+ RowStatus: &normalStatus,
+ HasParent: &hasParentFlag,
+ ExcludeContent: true,
}
if creatorID, err := util.ConvertStringToInt32(c.QueryParam("creatorId")); err == nil {
findMemoMessage.CreatorID = &creatorID
diff --git a/store/db/sqlite/memo.go b/store/db/sqlite/memo.go
index 1e315cbfe..cbf4fa61f 100644
--- a/store/db/sqlite/memo.go
+++ b/store/db/sqlite/memo.go
@@ -104,17 +104,23 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
}
orders = append(orders, "id DESC")
+ fields := []string{
+ `memo.id AS id`,
+ `memo.creator_id AS creator_id`,
+ `memo.created_ts AS created_ts`,
+ `memo.updated_ts AS updated_ts`,
+ `memo.row_status AS row_status`,
+ `memo.visibility AS visibility`,
+ }
+ if !find.ExcludeContent {
+ fields = append(fields, `memo.content AS content`)
+ }
+
query := `
SELECT
- memo.id AS id,
- memo.creator_id AS creator_id,
- memo.created_ts AS created_ts,
- memo.updated_ts AS updated_ts,
- memo.row_status AS row_status,
- memo.content AS content,
- memo.visibility AS visibility,
- CASE WHEN memo_organizer.pinned = 1 THEN 1 ELSE 0 END AS pinned,
- (
+ ` + strings.Join(fields, ", ") + `
+ CASE WHEN mo.pinned = 1 THEN 1 ELSE 0 END AS pinned,
+ (
SELECT
related_memo_id
FROM
@@ -122,26 +128,25 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
WHERE
memo_relation.memo_id = memo.id AND memo_relation.type = 'COMMENT'
LIMIT 1
- ) AS parent_id,
- GROUP_CONCAT(resource.id) AS resource_id_list,
- (
+ ) AS parent_id,
+ GROUP_CONCAT(resource.id) AS resource_id_list,
+ (
SELECT
- GROUP_CONCAT(memo_id || ':' || related_memo_id || ':' || type)
+ GROUP_CONCAT(memo_relation.memo_id || ':' || memo_relation.related_memo_id || ':' || memo_relation.type)
FROM
memo_relation
WHERE
memo_relation.memo_id = memo.id OR memo_relation.related_memo_id = memo.id
- ) AS relation_list
- FROM
- memo
- LEFT JOIN
- memo_organizer ON memo.id = memo_organizer.memo_id
- LEFT JOIN
- resource ON memo.id = resource.memo_id
- WHERE ` + strings.Join(where, " AND ") + `
- GROUP BY memo.id
- ORDER BY ` + strings.Join(orders, ", ") + `
- `
+ ) AS relation_list
+ FROM
+ memo
+ LEFT JOIN
+ memo_organizer mo ON memo.id = mo.memo_id
+ LEFT JOIN
+ resource ON memo.id = resource.memo_id
+ WHERE ` + strings.Join(where, " AND ") + `
+ GROUP BY memo.id
+ ORDER BY ` + strings.Join(orders, ", ")
if find.Limit != nil {
query = fmt.Sprintf("%s LIMIT %d", query, *find.Limit)
if find.Offset != nil {
@@ -160,19 +165,19 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
var memo store.Memo
var memoResourceIDList sql.NullString
var memoRelationList sql.NullString
- if err := rows.Scan(
+ dests := []any{
&memo.ID,
&memo.CreatorID,
&memo.CreatedTs,
&memo.UpdatedTs,
&memo.RowStatus,
- &memo.Content,
&memo.Visibility,
- &memo.Pinned,
- &memo.ParentID,
- &memoResourceIDList,
- &memoRelationList,
- ); err != nil {
+ }
+ if !find.ExcludeContent {
+ dests = append(dests, &memo.Content)
+ }
+ dests = append(dests, &memo.Pinned, &memo.ParentID, &memoResourceIDList, &memoRelationList)
+ if err := rows.Scan(dests...); err != nil {
return nil, err
}
diff --git a/store/memo.go b/store/memo.go
index e5afa05bb..35a6031be 100644
--- a/store/memo.go
+++ b/store/memo.go
@@ -64,6 +64,7 @@ type FindMemo struct {
VisibilityList []Visibility
Pinned *bool
HasParent *bool
+ ExcludeContent bool
// Pagination
Limit *int
diff --git a/web/src/pages/MemoDetail.tsx b/web/src/pages/MemoDetail.tsx
index 04f401d09..cd7de15f7 100644
--- a/web/src/pages/MemoDetail.tsx
+++ b/web/src/pages/MemoDetail.tsx
@@ -104,7 +104,7 @@ const MemoDetail = () => {
<>
<section className="relative top-0 w-full min-h-full overflow-x-hidden bg-zinc-100 dark:bg-zinc-900">
<div className="relative w-full h-auto mx-auto flex flex-col justify-start items-center bg-white dark:bg-zinc-700">
- <div className="w-full flex flex-col justify-start items-center py-8">
+ <div className="w-full flex flex-col justify-start items-center pt-16 pb-8">
<UserAvatar className="!w-20 h-auto mb-2 drop-shadow" avatarUrl={systemStatus.customizedProfile.logoUrl} />
<p className="text-3xl text-black opacity-80 dark:text-gray-200">{systemStatus.customizedProfile.name}</p>
</div>
@@ -186,7 +186,7 @@ const MemoDetail = () => {
</div>
</div>
</div>
- <div className="py-6 w-full border-t dark:border-t-zinc-700">
+ <div className="pt-8 pb-16 w-full border-t dark:border-t-zinc-700">
<div className="relative mx-auto flex-grow max-w-2xl w-full min-h-full flex flex-col justify-start items-start px-4 gap-y-1">
{comments.length === 0 ? (
<div className="w-full flex flex-col justify-center items-center py-6 mb-2">