From 46ce0bc62ef614e2bded49fe9277284aced151f0 Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 25 Oct 2025 06:47:06 +0800 Subject: [PATCH] fix(store): correct PostgreSQL placeholder generation in IN clauses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes a regression introduced in v0.25.2 where PostgreSQL IN clause placeholders were not properly incremented, causing all parameters to use the same placeholder index (e.g., $1, $1, $1 instead of $1, $2, $3). This bug affected: - ListReactions (ContentIDList) - caused "failed to list reactions" errors - ListAttachments (MemoIDList) - ListMemos (IDList and UIDList) The fix combines placeholder generation and argument appending into a single loop to ensure proper incrementing. Fixes #5188 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- store/db/postgres/attachment.go | 6 ++---- store/db/postgres/memo.go | 12 ++++-------- store/db/postgres/reaction.go | 10 +++------- 3 files changed, 9 insertions(+), 19 deletions(-) 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, `