fix(playlists): a replayed append whose reply was lost adds nothing more (#8122)

An append that reached the server but whose reply never reached the
phone stayed in the offline queue and was sent again, and since an
append is an action, the song landed twice. Android now names each
append with a request id, carried by the live send and its queued row
alike; POST /api/playlists/{id}/tracks takes it as request_id, and the
server records it per playlist in the append's own transaction
(playlist_append_requests, pruned after 30 days). A send whose id is
already recorded changes nothing; a failed append rolls its id back
with it. Without an id an append behaves as before, so queued rows
from older builds and Subsonic clients are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 11:52:12 -05:00
co-authored by Claude Opus 5.5
parent 6996561cb1
commit ad17849205
15 changed files with 207 additions and 20 deletions
+13
View File
@@ -113,6 +113,19 @@ JOIN artists ON artists.id = t.artist_id
WHERE t.id = sqlc.arg(track_id)::uuid
RETURNING *;
-- name: RecordPlaylistAppendRequest :execrows
-- Claims a client's append request id for the playlist. No row affected
-- means the id was already applied: the append is a replay.
INSERT INTO playlist_append_requests (playlist_id, request_id)
VALUES (sqlc.arg(playlist_id)::uuid, sqlc.arg(request_id)::uuid)
ON CONFLICT DO NOTHING;
-- name: PrunePlaylistAppendRequests :exec
-- Forgets the playlist's append request ids older than 30 days, by which
-- time any queued replay of them has long since been sent.
DELETE FROM playlist_append_requests
WHERE playlist_id = $1 AND created_at < now() - interval '30 days';
-- name: DeletePlaylistTrack :exec
-- Two-step: delete the row at `position`, then renumber subsequent rows
-- to close the gap. The renumber is a single UPDATE; the service layer