forked from Furumi/furumi-web
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>
58 lines
1.9 KiB
Rust
58 lines
1.9 KiB
Rust
//! Music library import: provider exports are stored as durable imports,
|
|
//! matched against the library and the federation, and published as ordinary
|
|
//! private playlists.
|
|
//!
|
|
//! The subsystem owns the `furumusic__library_import*` tables. It touches the
|
|
//! rest of Furumi only when publishing: target playlists, their tracks and the
|
|
//! existing Device Sync operations.
|
|
|
|
// Imports are processed by the resolver and publisher; until those are wired
|
|
// in, parts of the model and the storage layer are used by the tests only.
|
|
pub mod adapters;
|
|
mod handlers;
|
|
pub mod job;
|
|
pub mod matcher;
|
|
#[allow(dead_code)]
|
|
pub mod model;
|
|
pub mod providers;
|
|
pub mod publisher;
|
|
pub mod resolver;
|
|
#[allow(dead_code)]
|
|
pub mod store;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
pub use handlers::ImportApp;
|
|
pub use job::LibraryImportJob;
|
|
|
|
pub mod db_migrations {
|
|
use cot::db::migrations::{self, Operation, SyncDynMigration};
|
|
|
|
#[cot::db::migrations::migration_op]
|
|
async fn create_library_import(ctx: migrations::MigrationContext<'_>) -> cot::db::Result<()> {
|
|
for statement in include_str!("schema.sql").split(';') {
|
|
if !statement.trim().is_empty() {
|
|
ctx.db.raw(statement).await?;
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
pub struct M0065CreateLibraryImport;
|
|
impl migrations::Migration for M0065CreateLibraryImport {
|
|
const APP_NAME: &'static str = "furumusic";
|
|
const MIGRATION_NAME: &'static str = "m_0065_create_library_import";
|
|
const DEPENDENCIES: &'static [migrations::MigrationDependency] =
|
|
&[migrations::MigrationDependency::migration(
|
|
"furumusic",
|
|
"m_0064_review_dismissals",
|
|
)];
|
|
const OPERATIONS: &'static [Operation] =
|
|
&[Operation::custom(create_library_import).build()];
|
|
}
|
|
|
|
pub const MIGRATIONS: &[&SyncDynMigration] = &[&M0065CreateLibraryImport];
|
|
}
|