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

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 <noreply@anthropic.com>
release/0.25.2
Steven 2 weeks ago
parent 0c0d2a6294
commit 46ce0bc62e

@ -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")

@ -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)

@ -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 {
holders = append(holders, placeholder(len(args)+1))
}
if len(holders) > 0 {
where = append(where, "content_id IN ("+strings.Join(holders, ", ")+")")
for _, id := range find.ContentIDList {
holders = append(holders, placeholder(len(args)+1))
args = append(args, id)
}
}
where = append(where, "content_id IN ("+strings.Join(holders, ", ")+")")
}
rows, err := d.db.QueryContext(ctx, `

Loading…
Cancel
Save