feat: Your genres leads with the genres you play most, not A to Z
release / web (push) Successful in 1m8s
release / go (push) Successful in 1m40s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m43s
release / android (push) Successful in 4m21s
release / Build signed APK (push) Successful in 4m55s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 22s
release / Verify release artifacts (tag releases only) (push) Skipped
release / web (push) Successful in 1m8s
release / go (push) Successful in 1m40s
release / govulncheck (push) Successful in 18s
release / integration (push) Successful in 3m43s
release / android (push) Successful in 4m21s
release / Build signed APK (push) Successful in 4m55s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 22s
release / Verify release artifacts (tag releases only) (push) Skipped
The genre mix builder already ranks genres by how much you listen to them (taste profile, then plays and likes, then library size), but the rank was lost when the mixes were stored and both apps sorted the shelf by name. Each playlist now has a shelf_rank (migration 0107), which the genre builder fills 1..n in that listening order, even where it picked a narrower genre before a broader one. The list and detail endpoints carry it, and the web and Android Home sort the genre shelf by it, unranked playlists after by name. Android's playlist cache gains the column (Room v14). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -45,10 +45,14 @@ type playlistRowView struct {
|
||||
// before it already shows, so no cover repeats along the shelf.
|
||||
// Omitted when the playlist has none.
|
||||
CoverAlbumIDs []string `json:"cover_album_ids,omitempty"`
|
||||
TrackCount int32 `json:"track_count"`
|
||||
DurationSec int32 `json:"duration_sec"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
// ShelfRank is a system mix's place on its Home shelf, 1 first: genre
|
||||
// mixes are numbered by how much the user listens to each genre.
|
||||
// Omitted (0) for playlists the client orders itself.
|
||||
ShelfRank int32 `json:"shelf_rank,omitempty"`
|
||||
TrackCount int32 `json:"track_count"`
|
||||
DurationSec int32 `json:"duration_sec"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// playlistTrackView is one row of a playlist's track list on the wire.
|
||||
@@ -453,6 +457,7 @@ func playlistRowToView(r *playlists.PlaylistRow) playlistRowView {
|
||||
Kind: r.Kind,
|
||||
SystemVariant: r.SystemVariant,
|
||||
Refreshable: r.SystemVariant != nil && playlists.RefreshableSystemKind(*r.SystemVariant),
|
||||
ShelfRank: r.ShelfRank,
|
||||
TrackCount: r.TrackCount,
|
||||
DurationSec: r.DurationSec,
|
||||
CreatedAt: formatTimestamp(r.CreatedAt),
|
||||
|
||||
@@ -448,6 +448,7 @@ type Playlist struct {
|
||||
Kind string
|
||||
SystemVariant *string
|
||||
SeedArtistID pgtype.UUID
|
||||
ShelfRank int32
|
||||
}
|
||||
|
||||
type PlaylistTrack struct {
|
||||
|
||||
@@ -59,7 +59,7 @@ func (q *Queries) AppendPlaylistTrack(ctx context.Context, arg AppendPlaylistTra
|
||||
const createPlaylist = `-- name: CreatePlaylist :one
|
||||
INSERT INTO playlists (user_id, name, description, is_public)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id
|
||||
RETURNING id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id, shelf_rank
|
||||
`
|
||||
|
||||
type CreatePlaylistParams struct {
|
||||
@@ -91,6 +91,7 @@ func (q *Queries) CreatePlaylist(ctx context.Context, arg CreatePlaylistParams)
|
||||
&i.Kind,
|
||||
&i.SystemVariant,
|
||||
&i.SeedArtistID,
|
||||
&i.ShelfRank,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -132,7 +133,7 @@ func (q *Queries) DeletePlaylistTrack(ctx context.Context, arg DeletePlaylistTra
|
||||
}
|
||||
|
||||
const getPlaylist = `-- name: GetPlaylist :one
|
||||
SELECT p.id, p.user_id, p.name, p.description, p.is_public, p.cover_path, p.track_count, p.duration_sec, p.created_at, p.updated_at, p.kind, p.system_variant, p.seed_artist_id, u.username AS owner_username
|
||||
SELECT p.id, p.user_id, p.name, p.description, p.is_public, p.cover_path, p.track_count, p.duration_sec, p.created_at, p.updated_at, p.kind, p.system_variant, p.seed_artist_id, p.shelf_rank, u.username AS owner_username
|
||||
FROM playlists p
|
||||
JOIN users u ON u.id = p.user_id
|
||||
WHERE p.id = $1
|
||||
@@ -152,6 +153,7 @@ type GetPlaylistRow struct {
|
||||
Kind string
|
||||
SystemVariant *string
|
||||
SeedArtistID pgtype.UUID
|
||||
ShelfRank int32
|
||||
OwnerUsername string
|
||||
}
|
||||
|
||||
@@ -172,13 +174,14 @@ func (q *Queries) GetPlaylist(ctx context.Context, id pgtype.UUID) (GetPlaylistR
|
||||
&i.Kind,
|
||||
&i.SystemVariant,
|
||||
&i.SeedArtistID,
|
||||
&i.ShelfRank,
|
||||
&i.OwnerUsername,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getPlaylistsByIDs = `-- name: GetPlaylistsByIDs :many
|
||||
SELECT id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id FROM playlists WHERE id = ANY($1::uuid[])
|
||||
SELECT id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id, shelf_rank FROM playlists WHERE id = ANY($1::uuid[])
|
||||
`
|
||||
|
||||
// Batched lookup used by /api/library/sync to hydrate upsert payloads
|
||||
@@ -206,6 +209,7 @@ func (q *Queries) GetPlaylistsByIDs(ctx context.Context, dollar_1 []pgtype.UUID)
|
||||
&i.Kind,
|
||||
&i.SystemVariant,
|
||||
&i.SeedArtistID,
|
||||
&i.ShelfRank,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -380,7 +384,7 @@ func (q *Queries) ListPlaylistTracks(ctx context.Context, playlistID pgtype.UUID
|
||||
}
|
||||
|
||||
const listPlaylistsForUser = `-- name: ListPlaylistsForUser :many
|
||||
SELECT p.id, p.user_id, p.name, p.description, p.is_public, p.cover_path, p.track_count, p.duration_sec, p.created_at, p.updated_at, p.kind, p.system_variant, p.seed_artist_id, u.username AS owner_username
|
||||
SELECT p.id, p.user_id, p.name, p.description, p.is_public, p.cover_path, p.track_count, p.duration_sec, p.created_at, p.updated_at, p.kind, p.system_variant, p.seed_artist_id, p.shelf_rank, u.username AS owner_username
|
||||
FROM playlists p
|
||||
JOIN users u ON u.id = p.user_id
|
||||
WHERE p.user_id = $1 OR p.is_public = true
|
||||
@@ -401,6 +405,7 @@ type ListPlaylistsForUserRow struct {
|
||||
Kind string
|
||||
SystemVariant *string
|
||||
SeedArtistID pgtype.UUID
|
||||
ShelfRank int32
|
||||
OwnerUsername string
|
||||
}
|
||||
|
||||
@@ -429,6 +434,7 @@ func (q *Queries) ListPlaylistsForUser(ctx context.Context, userID pgtype.UUID)
|
||||
&i.Kind,
|
||||
&i.SystemVariant,
|
||||
&i.SeedArtistID,
|
||||
&i.ShelfRank,
|
||||
&i.OwnerUsername,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
@@ -480,7 +486,7 @@ SET
|
||||
is_public = CASE WHEN $5::boolean THEN $6::boolean ELSE is_public END,
|
||||
updated_at = now()
|
||||
WHERE id = $7
|
||||
RETURNING id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id
|
||||
RETURNING id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id, shelf_rank
|
||||
`
|
||||
|
||||
type UpdatePlaylistParams struct {
|
||||
@@ -521,6 +527,7 @@ func (q *Queries) UpdatePlaylist(ctx context.Context, arg UpdatePlaylistParams)
|
||||
&i.Kind,
|
||||
&i.SystemVariant,
|
||||
&i.SeedArtistID,
|
||||
&i.ShelfRank,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ func (q *Queries) ClearStaleSystemPlaylistInFlight(ctx context.Context) error {
|
||||
const createSystemPlaylist = `-- name: CreateSystemPlaylist :one
|
||||
INSERT INTO playlists (
|
||||
user_id, name, description, is_public,
|
||||
kind, system_variant, seed_artist_id, cover_path
|
||||
) VALUES ($1, $2, $6, false, 'system', $3, $4, $5)
|
||||
RETURNING id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id
|
||||
kind, system_variant, seed_artist_id, cover_path, shelf_rank
|
||||
) VALUES ($1, $2, $6, false, 'system', $3, $4, $5, $7)
|
||||
RETURNING id, user_id, name, description, is_public, cover_path, track_count, duration_sec, created_at, updated_at, kind, system_variant, seed_artist_id, shelf_rank
|
||||
`
|
||||
|
||||
type CreateSystemPlaylistParams struct {
|
||||
@@ -38,11 +38,13 @@ type CreateSystemPlaylistParams struct {
|
||||
SeedArtistID pgtype.UUID
|
||||
CoverPath *string
|
||||
Description string
|
||||
ShelfRank int32
|
||||
}
|
||||
|
||||
// Inserts a system-generated playlist. Used by BuildSystemPlaylists.
|
||||
// For 'for_you' variant, pass seed_artist_id as NULL (zero-value pgtype.UUID
|
||||
// with Valid=false).
|
||||
// with Valid=false). shelf_rank is the mix's place on its Home shelf, 1
|
||||
// first, or 0 for kinds the clients order themselves.
|
||||
func (q *Queries) CreateSystemPlaylist(ctx context.Context, arg CreateSystemPlaylistParams) (Playlist, error) {
|
||||
row := q.db.QueryRow(ctx, createSystemPlaylist,
|
||||
arg.UserID,
|
||||
@@ -51,6 +53,7 @@ func (q *Queries) CreateSystemPlaylist(ctx context.Context, arg CreateSystemPlay
|
||||
arg.SeedArtistID,
|
||||
arg.CoverPath,
|
||||
arg.Description,
|
||||
arg.ShelfRank,
|
||||
)
|
||||
var i Playlist
|
||||
err := row.Scan(
|
||||
@@ -67,6 +70,7 @@ func (q *Queries) CreateSystemPlaylist(ctx context.Context, arg CreateSystemPlay
|
||||
&i.Kind,
|
||||
&i.SystemVariant,
|
||||
&i.SeedArtistID,
|
||||
&i.ShelfRank,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE playlists DROP COLUMN shelf_rank;
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Where a system mix sits on its Home shelf, 1 first. The genre mix builder
|
||||
-- numbers its mixes by how much the user listens to each genre, so the
|
||||
-- "Your genres" shelf leads with their main genres rather than reading
|
||||
-- A to Z. 0 means unranked: every other playlist, which clients order their
|
||||
-- own way.
|
||||
ALTER TABLE playlists ADD COLUMN shelf_rank integer NOT NULL DEFAULT 0;
|
||||
@@ -253,11 +253,12 @@ SELECT id, user_id, name, description, is_public, kind, system_variant,
|
||||
-- name: CreateSystemPlaylist :one
|
||||
-- Inserts a system-generated playlist. Used by BuildSystemPlaylists.
|
||||
-- For 'for_you' variant, pass seed_artist_id as NULL (zero-value pgtype.UUID
|
||||
-- with Valid=false).
|
||||
-- with Valid=false). shelf_rank is the mix's place on its Home shelf, 1
|
||||
-- first, or 0 for kinds the clients order themselves.
|
||||
INSERT INTO playlists (
|
||||
user_id, name, description, is_public,
|
||||
kind, system_variant, seed_artist_id, cover_path
|
||||
) VALUES ($1, $2, sqlc.arg(description), false, 'system', $3, $4, $5)
|
||||
kind, system_variant, seed_artist_id, cover_path, shelf_rank
|
||||
) VALUES ($1, $2, sqlc.arg(description), false, 'system', $3, $4, $5, sqlc.arg(shelf_rank))
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetSystemPlaylistByVariantForUser :one
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
@@ -123,6 +124,10 @@ func produceGenreMixes(
|
||||
// shelf does not have yet. It takes tier-3 genres only while the shelf is
|
||||
// below genreMixMinShelf. build is handed the genres kept so far, whose songs
|
||||
// the new mix leaves out.
|
||||
//
|
||||
// The mixes it keeps are ranked for the shelf in the candidates' own order
|
||||
// (tier, then score: the genres the user listens to most first), not in the
|
||||
// order they were picked, which puts specific genres ahead of broad ones.
|
||||
func selectGenreMixes(
|
||||
cands []genreCandidate, build func(genreCandidate, []string) []rankedCandidate,
|
||||
) []builtPlaylist {
|
||||
@@ -136,6 +141,7 @@ func selectGenreMixes(
|
||||
owned := map[pgtype.UUID]struct{}{}
|
||||
kept := []string{}
|
||||
var out []builtPlaylist
|
||||
var picked []int // the candidate index of each mix in out
|
||||
for _, i := range specificFirst(cands, sets) {
|
||||
c := cands[i]
|
||||
if len(out) >= genreMixCount {
|
||||
@@ -160,10 +166,25 @@ func selectGenreMixes(
|
||||
Variant: "genre_mix",
|
||||
Tracks: tracks,
|
||||
})
|
||||
picked = append(picked, i)
|
||||
}
|
||||
rankByCandidate(out, picked)
|
||||
return out
|
||||
}
|
||||
|
||||
// rankByCandidate numbers each mix's ShelfRank from 1 by its candidate
|
||||
// index: the lower the index, the more the user listens to the genre.
|
||||
func rankByCandidate(out []builtPlaylist, picked []int) {
|
||||
order := make([]int, len(out))
|
||||
for k := range order {
|
||||
order[k] = k
|
||||
}
|
||||
sort.Slice(order, func(a, b int) bool { return picked[order[a]] < picked[order[b]] })
|
||||
for rank, k := range order {
|
||||
out[k].ShelfRank = int32(rank + 1)
|
||||
}
|
||||
}
|
||||
|
||||
// specificFirst returns the candidates' indexes in rank order, except that
|
||||
// within each tier the broad genres come after the specific ones.
|
||||
func specificFirst(cands []genreCandidate, sets []map[pgtype.UUID]struct{}) []int {
|
||||
|
||||
@@ -243,3 +243,24 @@ func TestSelectGenreMixes_LibraryGenresOnlyFillAShortShelf(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The shelf leads with the genre the user listens to most, even when it was
|
||||
// picked after narrower ones: Rock ranks first though Pop Punk was built
|
||||
// before it.
|
||||
func TestSelectGenreMixes_ShelfRankFollowsListeningNotPickOrder(t *testing.T) {
|
||||
cands := []genreCandidate{
|
||||
genreOf("Rock", 1, songs(1, 1000)), // broad: half its songs are Pop Punk
|
||||
genreOf("Pop Punk", 1, songs(1, 500)), // specific, so picked first
|
||||
genreOf("Jazz", 1, songs(3000, 3100)),
|
||||
}
|
||||
got := selectGenreMixes(cands, buildN(30))
|
||||
if names := labels(got); len(names) != 3 || names[0] != "Pop Punk mix" || names[2] != "Rock mix" {
|
||||
t.Fatalf("pick order = %v, want Pop Punk first and Rock last", names)
|
||||
}
|
||||
want := map[string]int32{"Rock mix": 1, "Pop Punk mix": 2, "Jazz mix": 3}
|
||||
for _, b := range got {
|
||||
if b.ShelfRank != want[b.Name] {
|
||||
t.Errorf("%s shelf rank = %d, want %d", b.Name, b.ShelfRank, want[b.Name])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,10 +80,13 @@ type PlaylistRow struct {
|
||||
// empty for a playlist with no covers, and on the rows Create and
|
||||
// Update return.
|
||||
CoverAlbumIDs []pgtype.UUID
|
||||
TrackCount int32
|
||||
DurationSec int32
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
// ShelfRank is a system mix's place on its Home shelf, 1 first; 0 for
|
||||
// playlists the clients order themselves. Only genre mixes are ranked.
|
||||
ShelfRank int32
|
||||
TrackCount int32
|
||||
DurationSec int32
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// PlaylistDetail extends PlaylistRow with the ordered track list.
|
||||
@@ -605,6 +608,7 @@ func playlistFromGetRow(r dbq.GetPlaylistRow) *PlaylistRow {
|
||||
SystemVariant: r.SystemVariant,
|
||||
SeedArtistID: r.SeedArtistID,
|
||||
CoverPath: r.CoverPath,
|
||||
ShelfRank: r.ShelfRank,
|
||||
TrackCount: r.TrackCount,
|
||||
DurationSec: r.DurationSec,
|
||||
CreatedAt: r.CreatedAt,
|
||||
@@ -624,6 +628,7 @@ func playlistFromListRow(r dbq.ListPlaylistsForUserRow) *PlaylistRow {
|
||||
SystemVariant: r.SystemVariant,
|
||||
SeedArtistID: r.SeedArtistID,
|
||||
CoverPath: r.CoverPath,
|
||||
ShelfRank: r.ShelfRank,
|
||||
TrackCount: r.TrackCount,
|
||||
DurationSec: r.DurationSec,
|
||||
CreatedAt: r.CreatedAt,
|
||||
|
||||
@@ -515,6 +515,9 @@ type builtPlaylist struct {
|
||||
Variant string
|
||||
SeedArtistID pgtype.UUID // zero value for non-seeded kinds
|
||||
Tracks []rankedCandidate
|
||||
// ShelfRank is the mix's place on its Home shelf, 1 first; 0 leaves
|
||||
// the order to the clients.
|
||||
ShelfRank int32
|
||||
}
|
||||
|
||||
// systemPlaylistProducer computes the playlists for one kind for a
|
||||
@@ -871,8 +874,7 @@ func BuildSystemPlaylists(ctx context.Context, pool *pgxpool.Pool, logger *slog.
|
||||
if len(bp.Tracks) == 0 {
|
||||
continue
|
||||
}
|
||||
id, err := insertSystemPlaylist(ctx, qtx, userID, bp.Name, bp.Variant,
|
||||
bp.SeedArtistID, bp.Tracks)
|
||||
id, err := insertSystemPlaylist(ctx, qtx, userID, bp)
|
||||
if err != nil {
|
||||
buildErr = fmt.Errorf("insert %s (%s): %w", bp.Variant, bp.Name, err)
|
||||
return buildErr
|
||||
@@ -1066,22 +1068,22 @@ func systemMixDescription(variant string) string {
|
||||
// in BuildSystemPlaylists overrides it with a 4-cell composite of the
|
||||
// contributing tracks' album art.
|
||||
func insertSystemPlaylist(ctx context.Context, qtx *dbq.Queries, userID pgtype.UUID,
|
||||
name, variant string, seedArtistID pgtype.UUID,
|
||||
tracks []rankedCandidate) (pgtype.UUID, error) {
|
||||
variantStr := variant
|
||||
bp builtPlaylist) (pgtype.UUID, error) {
|
||||
variantStr := bp.Variant
|
||||
p, err := qtx.CreateSystemPlaylist(ctx, dbq.CreateSystemPlaylistParams{
|
||||
UserID: userID,
|
||||
Name: name,
|
||||
Description: systemMixDescription(variant),
|
||||
Name: bp.Name,
|
||||
Description: systemMixDescription(bp.Variant),
|
||||
SystemVariant: &variantStr,
|
||||
SeedArtistID: seedArtistID,
|
||||
SeedArtistID: bp.SeedArtistID,
|
||||
CoverPath: nil,
|
||||
ShelfRank: bp.ShelfRank,
|
||||
})
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, fmt.Errorf("insert playlist row: %w", err)
|
||||
}
|
||||
|
||||
tracks, err = oneCopyPerSong(ctx, qtx, tracks)
|
||||
tracks, err := oneCopyPerSong(ctx, qtx, bp.Tracks)
|
||||
if err != nil {
|
||||
return pgtype.UUID{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user