feat(playlists): changes a phone queues offline are safe to send twice (#8023)
release / go (push) Successful in 1m59s
release / web (push) Successful in 1m23s
release / govulncheck (push) Successful in 22s
release / integration (push) Successful in 4m38s
release / android (push) Successful in 4m45s
release / Build signed APK (push) Successful in 5m22s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 17s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m59s
release / web (push) Successful in 1m23s
release / govulncheck (push) Successful in 22s
release / integration (push) Successful in 4m38s
release / android (push) Successful in 4m45s
release / Build signed APK (push) Successful in 5m22s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 17s
release / Verify release artifacts (tag releases only) (push) Skipped
- A new playlist can carry the client's own id; sending the create again finds the same list. - Removing a song can name the song expected at that position; if another song is there now, nothing is removed (409 list_changed). - A reorder can give the songs in their new order (track_ids); sending it again changes nothing. - The playlist service tells the owner's clients about every change itself, so a change made from a Subsonic app refreshes the web and Android apps too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,20 +57,26 @@ 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)
|
||||
INSERT INTO playlists (id, user_id, name, description, is_public)
|
||||
VALUES (COALESCE($1::uuid, gen_random_uuid()), $2, $3, $4, $5)
|
||||
ON CONFLICT (id) DO NOTHING
|
||||
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 {
|
||||
ID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Name string
|
||||
Description string
|
||||
IsPublic bool
|
||||
}
|
||||
|
||||
// id is the client's own id for the list, or NULL for a new one. A client
|
||||
// that made the list offline sends its id again on every retry, so an id
|
||||
// already taken inserts nothing and returns no row.
|
||||
func (q *Queries) CreatePlaylist(ctx context.Context, arg CreatePlaylistParams) (Playlist, error) {
|
||||
row := q.db.QueryRow(ctx, createPlaylist,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
@@ -309,6 +315,41 @@ func (q *Queries) ListPlaylistCoverAlbums(ctx context.Context, playlistIds []pgt
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listPlaylistEntriesForUpdate = `-- name: ListPlaylistEntriesForUpdate :many
|
||||
SELECT position, track_id
|
||||
FROM playlist_tracks
|
||||
WHERE playlist_id = $1
|
||||
ORDER BY position
|
||||
FOR UPDATE
|
||||
`
|
||||
|
||||
type ListPlaylistEntriesForUpdateRow struct {
|
||||
Position int32
|
||||
TrackID pgtype.UUID
|
||||
}
|
||||
|
||||
// The track at each position, locking the rows while a reorder rewrites
|
||||
// them.
|
||||
func (q *Queries) ListPlaylistEntriesForUpdate(ctx context.Context, playlistID pgtype.UUID) ([]ListPlaylistEntriesForUpdateRow, error) {
|
||||
rows, err := q.db.Query(ctx, listPlaylistEntriesForUpdate, playlistID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListPlaylistEntriesForUpdateRow
|
||||
for rows.Next() {
|
||||
var i ListPlaylistEntriesForUpdateRow
|
||||
if err := rows.Scan(&i.Position, &i.TrackID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listPlaylistTracks = `-- name: ListPlaylistTracks :many
|
||||
SELECT pt.playlist_id, pt.position, pt.track_id, pt.title, pt.artist_name, pt.album_title, pt.duration_sec, pt.added_at, pt.pick_kind,
|
||||
t.id AS live_track_id,
|
||||
|
||||
Reference in New Issue
Block a user