Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
fa2fa8a5
Unverified
Commit
fa2fa8a5
authored
Aug 04, 2025
by
varsnotwars
Committed by
GitHub
Aug 04, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: remove call to db for parent memo name (#4947)
parent
896a3dcc
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
18 deletions
+15
-18
memo_service_converter.go
server/router/api/v1/memo_service_converter.go
+3
-9
memo.go
store/db/mysql/memo.go
+4
-3
memo.go
store/db/postgres/memo.go
+3
-2
memo.go
store/db/sqlite/memo.go
+4
-3
memo.go
store/memo.go
+1
-1
No files found.
server/router/api/v1/memo_service_converter.go
View file @
fa2fa8a5
...
...
@@ -43,15 +43,9 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
memoMessage
.
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
}
...
...
store/db/mysql/memo.go
View file @
fa2fa8a5
...
...
@@ -90,7 +90,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
where
=
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_
u
id` 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_u
id`"
,
}
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.Memo
query
:=
"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
.
Parent
U
ID
,
}
if
!
find
.
ExcludeContent
{
dests
=
append
(
dests
,
&
memo
.
Content
)
...
...
store/db/postgres/memo.go
View file @
fa2fa8a5
...
...
@@ -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_u
id`
,
}
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.Memo
query
:=
`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
{
...
...
@@ -143,7 +144,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
&
memo
.
Visibility
,
&
memo
.
Pinned
,
&
payloadBytes
,
&
memo
.
ParentID
,
&
memo
.
Parent
U
ID
,
}
if
!
find
.
ExcludeContent
{
dests
=
append
(
dests
,
&
memo
.
Content
)
...
...
store/db/sqlite/memo.go
View file @
fa2fa8a5
...
...
@@ -82,7 +82,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
where
=
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_
u
id` 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_u
id`"
,
}
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.Memo
query
:=
"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
.
Parent
U
ID
,
}
if
!
find
.
ExcludeContent
{
dests
=
append
(
dests
,
&
memo
.
Content
)
...
...
store/memo.go
View file @
fa2fa8a5
...
...
@@ -52,7 +52,7 @@ type Memo struct {
Payload
*
storepb
.
MemoPayload
// Composed fields
Parent
ID
*
int32
Parent
UID
*
string
}
type
FindMemo
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment