Fixed: Correctly delete trackfiles on AlbumDeletedEvent

GetFilesByAlbum performs a join on the album releases under the hood,
which won't be populated once the album is deleted.  Fix by providing
a special delete method which omits the join and just looks at albumId.
pull/6/head
ta264 5 years ago
parent 3ebbf6ff83
commit 447bf63a4d

@ -6,6 +6,7 @@ using NzbDrone.Core.Qualities;
using NzbDrone.Core.Music;
using NzbDrone.Core.Test.Framework;
using System.Collections.Generic;
using System.Linq;
namespace NzbDrone.Core.Test.MediaFiles
{
@ -140,5 +141,14 @@ namespace NzbDrone.Core.Test.MediaFiles
file.Artist.Value.Metadata.Value.Should().NotBeNull();
}
}
[Test]
public void delete_files_by_album_should_work_if_join_fails()
{
Db.Delete(album);
Subject.DeleteFilesByAlbum(album.Id);
Db.All<TrackFile>().Where(x => x.AlbumId == album.Id).Should().HaveCount(0);
}
}
}

@ -14,6 +14,7 @@ namespace NzbDrone.Core.MediaFiles
List<TrackFile> GetFilesByRelease(int releaseId);
List<TrackFile> GetFilesWithBasePath(string path);
TrackFile GetFileWithPath(string path);
void DeleteFilesByAlbum(int albumId);
}
@ -51,6 +52,12 @@ namespace NzbDrone.Core.MediaFiles
.ToList();
}
public void DeleteFilesByAlbum(int albumId)
{
var ids = DataMapper.Query<TrackFile>().Where(x => x.AlbumId == albumId);
DeleteMany(ids);
}
public List<TrackFile> GetFilesByRelease(int releaseId)
{
return Query

@ -148,8 +148,7 @@ namespace NzbDrone.Core.MediaFiles
public void HandleAsync(AlbumDeletedEvent message)
{
var files = GetFilesByAlbum(message.Album.Id);
_mediaFileRepository.DeleteMany(files);
_mediaFileRepository.DeleteFilesByAlbum(message.Album.Id);
}
public List<TrackFile> GetFilesByArtist(int artistId)

Loading…
Cancel
Save