forked from Furumi/furumi-web
Publish matched import entries into private playlists over Device Sync
Each source playlist gets an ordinary private playlist, created with its
PlaylistCreated operation in one transaction even when nothing matched.
Matched entries follow in source order, at most 200 per transaction: the
playlist row, the item register, the existing PlaylistTrackAdded operation
and a receipt are written together, so fed_sync_ops serves as the outbox
and an interrupted batch leaves nothing behind. Locks are taken in a fixed
order (per-user advisory lock, import lease, playlist, fed-device identity,
registers). Registers are only inserted; an item the playlist has or had,
a removal committed to the journal but not yet applied, a repeat or a
receipt keep the publisher from adding it again. A deleted target pauses
publication until POST .../playlists/{pid}/recreate; POST .../resync
retries unmatched entries and appends new matches at the end.
Before each batch the outgoing Device Sync line is measured by serializing
the same parts the exchange sends. Tracks and new playlists are published
while the music snapshot stays within library_import_sync_budget (2 MiB)
and the whole line within 7 MiB; the rest waits as deferred_sync_limit.
Device Sync gets local helpers only: create_owned_playlist_tx is extracted
from the playlist handler, append_in_transaction takes an explicit
position, the two operations have in-transaction variants on
append_local_op, and applying a playlist item writes its register under an
atomic last-writer-wins condition and its playlist row in the same
transaction, so concurrent operations cannot make them diverge. The
protocol and its formats are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f10e384650
commit
4d6a1513d9
13 files changed
+3316
-45
No files matched your search
@@ -150,6 +150,25 @@ Doubtful entries keep up to five candidates. The import page lets the owner pick
|
||||
one; the choice is checked against the stored candidates and published like an
|
||||
automatic match.
|
||||
|
||||
Each source playlist becomes an ordinary private playlist, created even when
|
||||
nothing matched; Liked Songs becomes "Liked Songs (Spotify)". Matches are added
|
||||
in source order without repeats and reach paired devices through the usual
|
||||
Device Sync operations; unmatched entries stay in the import. Every added track
|
||||
is recorded together with its playlist row and its sync operation in one
|
||||
transaction, so an interrupted import never leaves half of it behind. **Retry
|
||||
unmatched** searches again and appends new matches at the end. Tracks the user
|
||||
added or removed in the playlist, on any device, are left as they are, and a
|
||||
deleted target playlist pauses publication until the owner asks to recreate it.
|
||||
|
||||
Device Sync sends every playlist item in each exchange and receivers reject
|
||||
lines over 8 MiB, so the import limits its share. Before each batch it measures
|
||||
the line the server would send: tracks are published while the music part of
|
||||
the sync snapshot stays within **2 MiB** and the whole line within 7 MiB; new
|
||||
playlists count as well. Set `FURU_LIBRARY_IMPORT_SYNC_BUDGET` (bytes) to change
|
||||
the 2 MiB budget. Tracks beyond it wait as "deferred" and are published by a
|
||||
later **Retry unmatched** when there is room again. About 3,000 federated
|
||||
tracks take 1.6 MiB.
|
||||
|
||||
## Federation
|
||||
|
||||
Federation is optional. Independent Furumusic and Furumi players that use the
|
||||
|
||||
@@ -169,6 +169,18 @@ pass, a stopped node, manual choices with tampered candidates, and cancellation
|
||||
that leaves no catalogue request running. The database needs the `pg_trgm`
|
||||
extension; the tests install it into `public`.
|
||||
|
||||
The publisher tests (`src/library_import/tests/publisher.rs`) run against the
|
||||
Device Sync tables of the same schema. They cover source order, repeats, empty
|
||||
playlists, a second pass that adds nothing, Resync appending at the end, tracks
|
||||
removed by the user or by a committed but not yet applied operation, deleted
|
||||
target playlists and recreation, an entry failing after its operation was
|
||||
recorded, registers written concurrently, deletions from the web and from
|
||||
another device during a batch, older operations that arrive during a batch,
|
||||
concurrent operations that must keep registers and playlist rows consistent,
|
||||
two imports of one user publishing in turn, and the Device Sync budget for
|
||||
tracks and playlists. `library_import_measures_the_outgoing_device_sync_line`
|
||||
prints the measured line for 3,200 published tracks with `--nocapture`.
|
||||
|
||||
`cargo test federation::client` checks bounded artist catalogue lookups without a
|
||||
database: at most 16 owners and the given number of parallel requests, timeouts,
|
||||
errors, oversized catalogues, and that dropping a lookup stops its search and
|
||||
|
||||
Reference in new issue
Block a user