mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
fix: prevent duplicate downloads by registering before releasing lock
- Move RegisterDownloadedSongAsync call before lock release - Prevents race condition where multiple threads download same song - Second thread now finds registered mapping before starting download - Fixes duplicate files like 'Song (1).flac', 'Song (2).flac' - Library scan and album download still happen after lock release
This commit is contained in:
@@ -298,6 +298,12 @@ public abstract class BaseDownloadService : IDownloadService
|
||||
|
||||
song.LocalPath = localPath;
|
||||
|
||||
// Register BEFORE releasing lock to prevent race conditions
|
||||
if (!isCache)
|
||||
{
|
||||
await LocalLibraryService.RegisterDownloadedSongAsync(song, localPath);
|
||||
}
|
||||
|
||||
// Check if this track belongs to a playlist and update M3U
|
||||
if (PlaylistSyncService != null)
|
||||
{
|
||||
@@ -316,11 +322,9 @@ public abstract class BaseDownloadService : IDownloadService
|
||||
}
|
||||
}
|
||||
|
||||
// Only register and scan if NOT in cache mode
|
||||
// Trigger library scan and album download AFTER releasing lock
|
||||
if (!isCache)
|
||||
{
|
||||
await LocalLibraryService.RegisterDownloadedSongAsync(song, localPath);
|
||||
|
||||
// Trigger a Subsonic library rescan (with debounce)
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user