Skip to main content

sync_library

Function sync_library 

Source
pub fn sync_library(
    db: &Database,
    client: &SubsonicClient,
    full: bool,
    server_url: &str,
    username: &str,
) -> Result<SyncResult, SyncError>
Expand description

Pull the Navidrome/Subsonic library into the local DB.

The album list is always walked in alphabeticalByName order: it is the one ordering stable under concurrent server-side inserts, so an offset walk can never skip an album that was added between two pages. An incremental sync walks the same list but only fetches details for albums created after last_sync — the list pages are cheap, the per-album fetches are not.

last_sync only advances when every album fetch succeeded. A run that lost albums to network errors leaves the timestamp alone so the next incremental sync re-fetches them, rather than writing a permanent hole in the library.

Deduplication happens in upsert_track — if a local track already exists with the same artist + album + title + track#, the remote_id and remote_url are merged onto the existing row instead of creating a duplicate.