Rewrites the internal/db/queries comments to rule 32 and regenerates dbq, whose doc comments and embedded SQL carry them. The bugs behind the tiered mixes, the md5 order seed, the score bands and the round-robin arms are restated as the constraint each one enforces; counts from one library and stale cross-references are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
3.8 KiB
Go
127 lines
3.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: suggestion_snoozes.sql
|
|
|
|
package dbq
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const gcDeleteExpiredSuggestionSnoozes = `-- name: GcDeleteExpiredSuggestionSnoozes :execrows
|
|
DELETE FROM suggestion_snoozes WHERE snoozed_until < now()
|
|
`
|
|
|
|
// Keeps the table from growing without bound. Every read already filters on
|
|
// snoozed_until > now(), so deleting an expired row changes no behaviour —
|
|
// this is purely reclamation.
|
|
func (q *Queries) GcDeleteExpiredSuggestionSnoozes(ctx context.Context) (int64, error) {
|
|
result, err := q.db.Exec(ctx, gcDeleteExpiredSuggestionSnoozes)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const listActiveSuggestionSnoozes = `-- name: ListActiveSuggestionSnoozes :many
|
|
SELECT candidate_mbid, candidate_name, snoozed_until, created_at
|
|
FROM suggestion_snoozes
|
|
WHERE user_id = $1 AND snoozed_until > now()
|
|
ORDER BY snoozed_until, candidate_mbid
|
|
`
|
|
|
|
type ListActiveSuggestionSnoozesRow struct {
|
|
CandidateMbid string
|
|
CandidateName string
|
|
SnoozedUntil pgtype.Timestamptz
|
|
CreatedAt pgtype.Timestamptz
|
|
}
|
|
|
|
// Backs the manage / un-snooze surface. Expired rows are filtered HERE
|
|
// rather than left to the sweeper: gc runs on an hourly tick, so a row can
|
|
// outlive its expiry by up to a tick and must not read as still-snoozed in
|
|
// the meantime.
|
|
func (q *Queries) ListActiveSuggestionSnoozes(ctx context.Context, userID pgtype.UUID) ([]ListActiveSuggestionSnoozesRow, error) {
|
|
rows, err := q.db.Query(ctx, listActiveSuggestionSnoozes, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListActiveSuggestionSnoozesRow
|
|
for rows.Next() {
|
|
var i ListActiveSuggestionSnoozesRow
|
|
if err := rows.Scan(
|
|
&i.CandidateMbid,
|
|
&i.CandidateName,
|
|
&i.SnoozedUntil,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const snoozeSuggestion = `-- name: SnoozeSuggestion :exec
|
|
|
|
INSERT INTO suggestion_snoozes (user_id, candidate_mbid, candidate_name, snoozed_until)
|
|
VALUES ($1, $2, $3, now() + ($4::float8 * INTERVAL '1 day'))
|
|
ON CONFLICT (user_id, candidate_mbid) DO UPDATE
|
|
SET snoozed_until = EXCLUDED.snoozed_until,
|
|
candidate_name = EXCLUDED.candidate_name
|
|
`
|
|
|
|
type SnoozeSuggestionParams struct {
|
|
UserID pgtype.UUID
|
|
CandidateMbid string
|
|
CandidateName string
|
|
Column4 float64
|
|
}
|
|
|
|
// Time-boxed "not right now" on a Discover artist suggestion.
|
|
//
|
|
// See 0049_suggestion_snoozes.up.sql for why this is a snooze and not a
|
|
// dismissal: it records no verdict on the music, expires on its own, and
|
|
// must never reach the taste profile. Nothing in internal/taste may read
|
|
// this table.
|
|
// Upsert, so re-snoozing an already-snoozed candidate EXTENDS it instead of
|
|
// erroring on the PK. The name is refreshed too — a later suggestion may
|
|
// carry a corrected spelling from the similarity feed.
|
|
// $1=user_id, $2=candidate_mbid, $3=candidate_name, $4=duration in days.
|
|
func (q *Queries) SnoozeSuggestion(ctx context.Context, arg SnoozeSuggestionParams) error {
|
|
_, err := q.db.Exec(ctx, snoozeSuggestion,
|
|
arg.UserID,
|
|
arg.CandidateMbid,
|
|
arg.CandidateName,
|
|
arg.Column4,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const unsnoozeSuggestion = `-- name: UnsnoozeSuggestion :execrows
|
|
DELETE FROM suggestion_snoozes
|
|
WHERE user_id = $1 AND candidate_mbid = $2
|
|
`
|
|
|
|
type UnsnoozeSuggestionParams struct {
|
|
UserID pgtype.UUID
|
|
CandidateMbid string
|
|
}
|
|
|
|
// Row count is returned so the handler can 404 an MBID that was never
|
|
// snoozed rather than reporting success for a no-op.
|
|
func (q *Queries) UnsnoozeSuggestion(ctx context.Context, arg UnsnoozeSuggestionParams) (int64, error) {
|
|
result, err := q.db.Exec(ctx, unsnoozeSuggestion, arg.UserID, arg.CandidateMbid)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|