feat(subsonic): an artist's top songs, and the play queue carried between devices
release / go (push) Successful in 1m50s
release / web (push) Successful in 1m14s
release / govulncheck (push) Successful in 44s
release / integration (push) Successful in 4m11s
release / android (push) Successful in 6m15s
release / Build signed APK (push) Successful in 7m51s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m50s
release / web (push) Successful in 1m14s
release / govulncheck (push) Successful in 44s
release / integration (push) Successful in 4m11s
release / android (push) Successful in 6m15s
release / Build signed APK (push) Successful in 7m51s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
getTopSongs ranks the named artist's songs by how often they were played through on this server, then by likes, then in album order, so an artist nobody has played yet still has songs to offer. Missing files and the listener's quarantined songs are left out. savePlayQueue keeps one queue per listener: the songs in order, the one playing, how far into it, and the app that saved it. getPlayQueue gives it back to that listener only; a song no longer in the library drops out. Saving no songs clears it. The queue lives in a new play_queues table, which backups carry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -411,6 +411,15 @@ type PlayEvent struct {
|
||||
DeviceClass *string
|
||||
}
|
||||
|
||||
type PlayQueue struct {
|
||||
UserID pgtype.UUID
|
||||
TrackIds []pgtype.UUID
|
||||
CurrentTrackID pgtype.UUID
|
||||
PositionMs int64
|
||||
ChangedAt pgtype.Timestamptz
|
||||
ChangedBy string
|
||||
}
|
||||
|
||||
type PlaySession struct {
|
||||
ID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: play_queue.sql
|
||||
|
||||
package dbq
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deletePlayQueue = `-- name: DeletePlayQueue :exec
|
||||
DELETE FROM play_queues WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeletePlayQueue(ctx context.Context, userID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deletePlayQueue, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getPlayQueue = `-- name: GetPlayQueue :one
|
||||
SELECT user_id, track_ids, current_track_id, position_ms, changed_at, changed_by FROM play_queues WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetPlayQueue(ctx context.Context, userID pgtype.UUID) (PlayQueue, error) {
|
||||
row := q.db.QueryRow(ctx, getPlayQueue, userID)
|
||||
var i PlayQueue
|
||||
err := row.Scan(
|
||||
&i.UserID,
|
||||
&i.TrackIds,
|
||||
&i.CurrentTrackID,
|
||||
&i.PositionMs,
|
||||
&i.ChangedAt,
|
||||
&i.ChangedBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const savePlayQueue = `-- name: SavePlayQueue :exec
|
||||
INSERT INTO play_queues (user_id, track_ids, current_track_id, position_ms, changed_at, changed_by)
|
||||
VALUES ($1, $2::uuid[], $3, $4, now(), $5)
|
||||
ON CONFLICT (user_id) DO UPDATE
|
||||
SET track_ids = EXCLUDED.track_ids,
|
||||
current_track_id = EXCLUDED.current_track_id,
|
||||
position_ms = EXCLUDED.position_ms,
|
||||
changed_at = EXCLUDED.changed_at,
|
||||
changed_by = EXCLUDED.changed_by
|
||||
`
|
||||
|
||||
type SavePlayQueueParams struct {
|
||||
UserID pgtype.UUID
|
||||
TrackIds []pgtype.UUID
|
||||
CurrentTrackID pgtype.UUID
|
||||
PositionMs int64
|
||||
ChangedBy string
|
||||
}
|
||||
|
||||
// Replaces the user's saved queue.
|
||||
func (q *Queries) SavePlayQueue(ctx context.Context, arg SavePlayQueueParams) error {
|
||||
_, err := q.db.Exec(ctx, savePlayQueue,
|
||||
arg.UserID,
|
||||
arg.TrackIds,
|
||||
arg.CurrentTrackID,
|
||||
arg.PositionMs,
|
||||
arg.ChangedBy,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -833,6 +833,96 @@ func (q *Queries) ListSuspectSourceTracks(ctx context.Context, arg ListSuspectSo
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTopTracksForArtistName = `-- name: ListTopTracksForArtistName :many
|
||||
SELECT t.id, t.title, t.album_id, t.artist_id, t.track_number, t.disc_number, t.duration_ms, t.file_path, t.file_size, t.file_format, t.bitrate, t.mbid, t.genre, t.added_at, t.updated_at, t.tag_source, t.tag_sources_version, t.tag_read_version, t.missing_since, t.mbid_source, t.song_id, t.song_key, t.source_verdict, t.source_verdict_at, t.emptied_at, t.removed_reason, t.removed_by, t.artist_credit
|
||||
FROM tracks t
|
||||
JOIN artists ar ON ar.id = t.artist_id
|
||||
JOIN albums al ON al.id = t.album_id
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT count(*) AS plays FROM play_events pe
|
||||
WHERE pe.track_id = t.id AND pe.was_skipped = false
|
||||
) p ON true
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT count(*) AS likes FROM general_likes gl WHERE gl.track_id = t.id
|
||||
) l ON true
|
||||
WHERE lower(ar.name) = lower($1::text)
|
||||
AND t.missing_since IS NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM quarantine q
|
||||
WHERE q.user_id = $2 AND q.track_id = t.id
|
||||
)
|
||||
ORDER BY p.plays DESC, l.likes DESC,
|
||||
al.release_date NULLS LAST, al.sort_title, al.id,
|
||||
t.disc_number NULLS FIRST, t.track_number NULLS FIRST, t.id
|
||||
LIMIT $3
|
||||
`
|
||||
|
||||
type ListTopTracksForArtistNameParams struct {
|
||||
ArtistName string
|
||||
UserID pgtype.UUID
|
||||
Lim int32
|
||||
}
|
||||
|
||||
type ListTopTracksForArtistNameRow struct {
|
||||
Track Track
|
||||
}
|
||||
|
||||
// An artist's top songs for the Subsonic getTopSongs, which names the artist
|
||||
// rather than giving an id; the name matches regardless of case. "Top" is
|
||||
// this server's own listening: the songs played through most often (skips
|
||||
// not counted) by everyone on it, then the most liked. Songs nobody has
|
||||
// played or liked follow in album order, so an artist with no history still
|
||||
// has songs to play. Missing files and the listener's quarantined songs are
|
||||
// left out.
|
||||
func (q *Queries) ListTopTracksForArtistName(ctx context.Context, arg ListTopTracksForArtistNameParams) ([]ListTopTracksForArtistNameRow, error) {
|
||||
rows, err := q.db.Query(ctx, listTopTracksForArtistName, arg.ArtistName, arg.UserID, arg.Lim)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListTopTracksForArtistNameRow
|
||||
for rows.Next() {
|
||||
var i ListTopTracksForArtistNameRow
|
||||
if err := rows.Scan(
|
||||
&i.Track.ID,
|
||||
&i.Track.Title,
|
||||
&i.Track.AlbumID,
|
||||
&i.Track.ArtistID,
|
||||
&i.Track.TrackNumber,
|
||||
&i.Track.DiscNumber,
|
||||
&i.Track.DurationMs,
|
||||
&i.Track.FilePath,
|
||||
&i.Track.FileSize,
|
||||
&i.Track.FileFormat,
|
||||
&i.Track.Bitrate,
|
||||
&i.Track.Mbid,
|
||||
&i.Track.Genre,
|
||||
&i.Track.AddedAt,
|
||||
&i.Track.UpdatedAt,
|
||||
&i.Track.TagSource,
|
||||
&i.Track.TagSourcesVersion,
|
||||
&i.Track.TagReadVersion,
|
||||
&i.Track.MissingSince,
|
||||
&i.Track.MbidSource,
|
||||
&i.Track.SongID,
|
||||
&i.Track.SongKey,
|
||||
&i.Track.SourceVerdict,
|
||||
&i.Track.SourceVerdictAt,
|
||||
&i.Track.EmptiedAt,
|
||||
&i.Track.RemovedReason,
|
||||
&i.Track.RemovedBy,
|
||||
&i.Track.ArtistCredit,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listTrackPathsForReconcile = `-- name: ListTrackPathsForReconcile :many
|
||||
SELECT id, file_path, missing_since FROM tracks
|
||||
`
|
||||
|
||||
Reference in New Issue
Block a user