Unify storage ID queries under one implementation

This commit is contained in:
Ian Gulliver
2026-10-21 11:58:42 -07:00
parent 069474e6aa
commit abe4d7c9d5
6 changed files with 37 additions and 117 deletions
+2 -34
View File
@@ -95,23 +95,7 @@ func (s *Store) ListInbox(ctx context.Context, f InboxFilter) ([]api.InboxItem,
args = append(args, f.SessionID)
}
rows, err := s.db.QueryContext(ctx, `SELECT id FROM inbox_items WHERE `+strings.Join(where, " AND ")+` ORDER BY created_at`, args...)
if err != nil {
return nil, err
}
ids := []string{}
for rows.Next() {
id := ""
err = rows.Scan(&id)
if err != nil {
rows.Close()
return nil, err
}
ids = append(ids, id)
}
rows.Close()
err = rows.Err()
ids, err := queryIDs(ctx, s.db, `SELECT id FROM inbox_items WHERE `+strings.Join(where, " AND ")+` ORDER BY created_at`, args...)
if err != nil {
return nil, err
}
@@ -230,21 +214,10 @@ func (s *Store) DismissItem(ctx context.Context, id, actor string) error {
}
func dismissTaskInbox(ctx context.Context, tx *sql.Tx, emit emitFunc, taskID, actor string) error {
ids := []string{}
rows, err := tx.QueryContext(ctx, `SELECT id FROM inbox_items WHERE task_id = ? AND state = ?`, taskID, string(api.Open))
ids, err := queryIDs(ctx, tx, `SELECT id FROM inbox_items WHERE task_id = ? AND state = ?`, taskID, string(api.Open))
if err != nil {
return err
}
for rows.Next() {
id := ""
err = rows.Scan(&id)
if err != nil {
rows.Close()
return err
}
ids = append(ids, id)
}
rows.Close()
for _, id := range ids {
_, err = tx.ExecContext(ctx, `UPDATE inbox_items SET state = ?, resolved_by = ?, resolved_at = ? WHERE id = ?`,
@@ -346,11 +319,6 @@ func (s *Store) MarkUndelivered(ctx context.Context, responseIDs []string) error
})
}
type querier interface {
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
func getItem(ctx context.Context, q querier, id string) (api.InboxItem, error) {
item := api.InboxItem{}
payload := ""