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.

fix(store): correct PostgreSQL placeholder generation in IN clauses

Steven46ce0bc62ef6
diff --git a/store/db/postgres/attachment.go b/store/db/postgres/attachment.go
index 44362cc00..1c17941d6 100644
--- a/store/db/postgres/attachment.go
+++ b/store/db/postgres/attachment.go
@@ -59,13 +59,11 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
}
if len(find.MemoIDList) > 0 {
holders := make([]string, 0, len(find.MemoIDList))
- for range find.MemoIDList {
- holders = append(holders, placeholder(len(args)+1))
- }
- where = append(where, "resource.memo_id IN ("+strings.Join(holders, ", ")+")")
for _, id := range find.MemoIDList {
+ holders = append(holders, placeholder(len(args)+1))
args = append(args, id)
}
+ where = append(where, "resource.memo_id IN ("+strings.Join(holders, ", ")+")")
}
if find.HasRelatedMemo {
where = append(where, "resource.memo_id IS NOT NULL")
diff --git a/store/db/postgres/memo.go b/store/db/postgres/memo.go
index ac4da8f25..3fa3abd4b 100644
--- a/store/db/postgres/memo.go
+++ b/store/db/postgres/memo.go
@@ -53,26 +53,22 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
}
if len(find.IDList) > 0 {
holders := make([]string, 0, len(find.IDList))
- for range find.IDList {
- holders = append(holders, placeholder(len(args)+1))
- }
- where = append(where, "memo.id IN ("+strings.Join(holders, ", ")+")")
for _, id := range find.IDList {
+ holders = append(holders, placeholder(len(args)+1))
args = append(args, id)
}
+ where = append(where, "memo.id IN ("+strings.Join(holders, ", ")+")")
}
if v := find.UID; v != nil {
where, args = append(where, "memo.uid = "+placeholder(len(args)+1)), append(args, *v)
}
if len(find.UIDList) > 0 {
holders := make([]string, 0, len(find.UIDList))
- for range find.UIDList {
- holders = append(holders, placeholder(len(args)+1))
- }
- where = append(where, "memo.uid IN ("+strings.Join(holders, ", ")+")")
for _, uid := range find.UIDList {
+ holders = append(holders, placeholder(len(args)+1))
args = append(args, uid)
}
+ where = append(where, "memo.uid IN ("+strings.Join(holders, ", ")+")")
}
if v := find.CreatorID; v != nil {
where, args = append(where, "memo.creator_id = "+placeholder(len(args)+1)), append(args, *v)
diff --git a/store/db/postgres/reaction.go b/store/db/postgres/reaction.go
index 3ff6354cb..e2b64737c 100644
--- a/store/db/postgres/reaction.go
+++ b/store/db/postgres/reaction.go
@@ -36,15 +36,11 @@ func (d *DB) ListReactions(ctx context.Context, find *store.FindReaction) ([]*st
}
if len(find.ContentIDList) > 0 {
holders := make([]string, 0, len(find.ContentIDList))
- for range find.ContentIDList {
+ for _, id := range find.ContentIDList {
holders = append(holders, placeholder(len(args)+1))
+ args = append(args, id)
}
- if len(holders) > 0 {
- where = append(where, "content_id IN ("+strings.Join(holders, ", ")+")")
- for _, id := range find.ContentIDList {
- args = append(args, id)
- }
- }
+ where = append(where, "content_id IN ("+strings.Join(holders, ", ")+")")
}
rows, err := d.db.QueryContext(ctx, `