Files
minstrel/internal/db/dbq/admin_status.sql.go
T
bvandeusenandClaude Opus 5.5 55c7497ca7
release / go (push) Successful in 1m54s
release / web (push) Failing after 5s
release / integration (push) Failing after 3m44s
release / govulncheck (push) Successful in 20s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 19s
release / android (push) Canceled after 2m37s
feat: Minstrel stops acquiring music and drops Discover
Minstrel is now a viewer of the library it is pointed at. Finding,
downloading and filing music moves out of it.

Removed from the server:
- the request flow (requests, approval, auto-approve) and the wanted list,
  follows, release profiles and release blocks;
- searching indexers, the download clients, the importer, the album
  lifecycle and missing-file re-acquisition;
- the catalogue's discography, search and art (the MusicBrainz release and
  track-list cache stays, for the duplicate resolver);
- Discover: its suggestions of artists not in the library, snoozes, the
  candidate-artist tag enrichment and its tuning scope;
- writes to acquisition tables from moving the library folder and from
  merging duplicates, the want-list join on Suspect sources, the sealing of
  acquisition credentials, and the release-group lookup only
  re-acquisition used.

Settling a wrong-slot duplicate no longer sets the release aside: the
copies go and their slots show as missing until a good copy is in the
library.

Removed from the web: Admin > Acquisition and Requests, /requests,
/discover, Follow on the artist page, the auto-approve toggle, and the
Collection's wanted-list tabs. The Collection is now the library's health:
an overview, Reports, Duplicates, Suspect sources and Missing files. The
README and docs no longer describe getting music.

The tables stay for now; a later migration drops them. The request
notification kinds and the Android screens are still to go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 20:51:14 -05:00

133 lines
3.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: admin_status.sql
package dbq
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const libraryStatus = `-- name: LibraryStatus :one
SELECT COUNT(*)::bigint AS tracks,
COUNT(DISTINCT album_id)::bigint AS albums,
COUNT(DISTINCT artist_id)::bigint AS artists,
COALESCE(SUM(file_size), 0)::bigint AS bytes
FROM tracks
WHERE missing_since IS NULL
`
type LibraryStatusRow struct {
Tracks int64
Albums int64
Artists int64
Bytes int64
}
// What the library holds on disk: tracks whose files are present, the
// albums and artists they make, and their size.
func (q *Queries) LibraryStatus(ctx context.Context) (LibraryStatusRow, error) {
row := q.db.QueryRow(ctx, libraryStatus)
var i LibraryStatusRow
err := row.Scan(
&i.Tracks,
&i.Albums,
&i.Artists,
&i.Bytes,
)
return i, err
}
const listListeningNow = `-- name: ListListeningNow :many
SELECT pe.started_at, pe.client_id, pe.device_class,
u.username,
t.id AS track_id, t.title AS track_title, t.duration_ms,
ar.name AS artist_name,
al.id AS album_id, al.title AS album_title
FROM play_events pe
JOIN users u ON u.id = pe.user_id
JOIN tracks t ON t.id = pe.track_id
JOIN albums al ON al.id = t.album_id
JOIN artists ar ON ar.id = t.artist_id
WHERE pe.ended_at IS NULL
AND pe.started_at > now() - INTERVAL '24 hours'
AND pe.started_at + make_interval(secs => t.duration_ms / 1000.0) + INTERVAL '5 minutes' > now()
ORDER BY pe.started_at DESC
LIMIT 20
`
type ListListeningNowRow struct {
StartedAt pgtype.Timestamptz
ClientID *string
DeviceClass *string
Username string
TrackID pgtype.UUID
TrackTitle string
DurationMs int32
ArtistName string
AlbumID pgtype.UUID
AlbumTitle string
}
// The admin Overview's status sections: who is listening and what the
// library holds. Each is one cheap read.
// Plays in progress: open play events still inside their track's length,
// with a few minutes' grace for a pause. A client that never says a play
// ended would otherwise read as listening until the 24-hour sweep closes it.
func (q *Queries) ListListeningNow(ctx context.Context) ([]ListListeningNowRow, error) {
rows, err := q.db.Query(ctx, listListeningNow)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListListeningNowRow
for rows.Next() {
var i ListListeningNowRow
if err := rows.Scan(
&i.StartedAt,
&i.ClientID,
&i.DeviceClass,
&i.Username,
&i.TrackID,
&i.TrackTitle,
&i.DurationMs,
&i.ArtistName,
&i.AlbumID,
&i.AlbumTitle,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const playsLastDay = `-- name: PlaysLastDay :one
SELECT COUNT(*)::bigint AS plays,
COUNT(DISTINCT user_id)::bigint AS listeners,
MAX(started_at)::timestamptz AS last_at
FROM play_events
WHERE started_at > now() - INTERVAL '24 hours'
`
type PlaysLastDayRow struct {
Plays int64
Listeners int64
LastAt pgtype.Timestamptz
}
// The last day's listening, for the line under Listening now.
func (q *Queries) PlaysLastDay(ctx context.Context) (PlaysLastDayRow, error) {
row := q.db.QueryRow(ctx, playsLastDay)
var i PlaysLastDayRow
err := row.Scan(&i.Plays, &i.Listeners, &i.LastAt)
return i, err
}