Rewrite offline playlist system to use file paths instead of IDs

Problem: Pending playlists created offline used auto-increment track IDs,
which change on library re-scans, causing FOREIGN KEY errors and data loss.

Solution: Store file_path instead of IDs for local tracks. Paths are stable
identifiers that only change if files are moved/renamed.

Backend changes:
- Add local_track_paths TEXT column to pending_playlist_sync table
- Update PendingPlaylist struct to include local_track_paths field
- Modify create/add functions to accept paths instead of IDs
- Add get_track_by_path command to resolve paths to current IDs
- Keep local_track_ids for backward compatibility

Frontend changes:
- Update PendingPlaylist interface with localTrackPaths field
- Fetch file paths from track IDs before creating pending playlists
- Implement path-to-ID resolution in sync function
- Gracefully handle missing files (log warning and skip)
- Backward compatible with old ID-based pending playlists

Testing:
- Simulated playlist creation with 3 local tracks (IDs 197-199)
- Simulated re-scan by changing IDs to 1500-1502
- Verified path resolution finds tracks with new IDs correctly
- Verified missing files are handled gracefully

This makes the offline playlist system robust and production-ready.
This commit is contained in:
vicrodh committed 2026-01-20 13:30:10 -06:00
1 parent 8a6816d8d3
commit c1d32b4181
11 files changed
+481 -111

No files matched your search

+24
View File
@@ -131,3 +131,27 @@ pub async fn update_playlist(
.await
.map_err(|e| format!("Failed to update playlist: {}", e))
}
/// Get multiple tracks by their IDs
#[tauri::command]
pub async fn get_tracks_by_ids(
track_ids: Vec<u64>,
state: State<'_, AppState>,
) -> Result<Vec<crate::api::models::Track>, String> {
log::info!("Command: get_tracks_by_ids ({} tracks)", track_ids.len());
let client = state.client.lock().await;
let mut tracks = Vec::new();
for track_id in track_ids {
match client.get_track(track_id).await {
Ok(track) => tracks.push(track),
Err(e) => {
log::warn!("Failed to get track {}: {}", track_id, e);
// Continue with other tracks even if one fails
}
}
}
Ok(tracks)
}