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.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
refactor: remove call to db for parent memo name (#4947)
varsnotwarsfa2fa8a5d774
diff --git a/server/router/api/v1/memo_service_converter.go b/server/router/api/v1/memo_service_converter.goindex c8433c3a2..139cbfaba 100644--- a/server/router/api/v1/memo_service_converter.go+++ b/server/router/api/v1/memo_service_converter.go@@ -43,15 +43,9 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.MemmemoMessage.Property = convertMemoPropertyFromStore(memo.Payload.Property)memoMessage.Location = convertLocationFromStore(memo.Payload.Location)}- if memo.ParentID != nil {- parent, err := s.Store.GetMemo(ctx, &store.FindMemo{- ID: memo.ParentID,- ExcludeContent: true,- })- if err != nil {- return nil, errors.Wrap(err, "failed to get parent memo")- }- parentName := fmt.Sprintf("%s%s", MemoNamePrefix, parent.UID)++ if memo.ParentUID != nil {+ parentName := fmt.Sprintf("%s%s", MemoNamePrefix, *memo.ParentUID)memoMessage.Parent = &parentName}diff --git a/store/db/mysql/memo.go b/store/db/mysql/memo.goindex 7d59e431b..354aab545 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.Memowhere = append(where, fmt.Sprintf("`memo`.`visibility` in (%s)", strings.Join(placeholder, ",")))}if find.ExcludeComments {- having = append(having, "`parent_id` IS NULL")+ having = append(having, "`parent_uid` IS NULL")}order := "DESC"@@ -113,7 +113,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo"`memo`.`visibility` AS `visibility`","`memo`.`pinned` AS `pinned`","`memo`.`payload` AS `payload`",- "`memo_relation`.`related_memo_id` AS `parent_id`",+ "CASE WHEN `parent_memo`.`uid` IS NOT NULL THEN `parent_memo`.`uid` ELSE NULL END AS `parent_uid`",}if !find.ExcludeContent {fields = append(fields, "`memo`.`content` AS `content`")@@ -121,6 +121,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memoquery := "SELECT " + strings.Join(fields, ", ") + " FROM `memo`" + " " +"LEFT JOIN `memo_relation` ON `memo`.`id` = `memo_relation`.`memo_id` AND `memo_relation`.`type` = 'COMMENT'" + " " ++ "LEFT JOIN `memo` AS `parent_memo` ON `memo_relation`.`related_memo_id` = `parent_memo`.`id`" + " " +"WHERE " + strings.Join(where, " AND ") + " " +"HAVING " + strings.Join(having, " AND ") + " " +"ORDER BY " + strings.Join(orderBy, ", ")@@ -151,7 +152,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo&memo.Visibility,&memo.Pinned,&payloadBytes,- &memo.ParentID,+ &memo.ParentUID,}if !find.ExcludeContent {dests = append(dests, &memo.Content)diff --git a/store/db/postgres/memo.go b/store/db/postgres/memo.goindex b30d0bc11..0400165a7 100644--- a/store/db/postgres/memo.go+++ b/store/db/postgres/memo.go@@ -105,7 +105,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo`memo.visibility AS visibility`,`memo.pinned AS pinned`,`memo.payload AS payload`,- `memo_relation.related_memo_id AS parent_id`,+ `CASE WHEN parent_memo.uid IS NOT NULL THEN parent_memo.uid ELSE NULL END AS parent_uid`,}if !find.ExcludeContent {fields = append(fields, `memo.content AS content`)@@ -114,6 +114,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memoquery := `SELECT ` + strings.Join(fields, ", ") + `FROM memoLEFT JOIN memo_relation ON memo.id = memo_relation.memo_id AND memo_relation.type = 'COMMENT'+ LEFT JOIN memo AS parent_memo ON memo_relation.related_memo_id = parent_memo.idWHERE ` + strings.Join(where, " AND ") + `ORDER BY ` + strings.Join(orderBy, ", ")if find.Limit != nil {@@ -143,7 +144,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo&memo.Visibility,&memo.Pinned,&payloadBytes,- &memo.ParentID,+ &memo.ParentUID,}if !find.ExcludeContent {dests = append(dests, &memo.Content)diff --git a/store/db/sqlite/memo.go b/store/db/sqlite/memo.goindex 73f628a7e..74e0b87b6 100644--- a/store/db/sqlite/memo.go+++ b/store/db/sqlite/memo.go@@ -82,7 +82,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memowhere = append(where, fmt.Sprintf("`memo`.`visibility` IN (%s)", strings.Join(placeholder, ",")))}if find.ExcludeComments {- where = append(where, "`parent_id` IS NULL")+ where = append(where, "`parent_uid` IS NULL")}order := "DESC"@@ -105,7 +105,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo"`memo`.`visibility` AS `visibility`","`memo`.`pinned` AS `pinned`","`memo`.`payload` AS `payload`",- "`memo_relation`.`related_memo_id` AS `parent_id`",+ "CASE WHEN `parent_memo`.`uid` IS NOT NULL THEN `parent_memo`.`uid` ELSE NULL END AS `parent_uid`",}if !find.ExcludeContent {fields = append(fields, "`memo`.`content` AS `content`")@@ -113,6 +113,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memoquery := "SELECT " + strings.Join(fields, ", ") + "FROM `memo` " +"LEFT JOIN `memo_relation` ON `memo`.`id` = `memo_relation`.`memo_id` AND `memo_relation`.`type` = \"COMMENT\" " ++ "LEFT JOIN `memo` AS `parent_memo` ON `memo_relation`.`related_memo_id` = `parent_memo`.`id` " +"WHERE " + strings.Join(where, " AND ") + " " +"ORDER BY " + strings.Join(orderBy, ", ")if find.Limit != nil {@@ -142,7 +143,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo&memo.Visibility,&memo.Pinned,&payloadBytes,- &memo.ParentID,+ &memo.ParentUID,}if !find.ExcludeContent {dests = append(dests, &memo.Content)diff --git a/store/memo.go b/store/memo.goindex a3a10a075..bdff1f106 100644--- a/store/memo.go+++ b/store/memo.go@@ -52,7 +52,7 @@ type Memo struct {Payload *storepb.MemoPayload// Composed fields- ParentID *int32+ ParentUID *string}type FindMemo struct {