mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-26 07:42:49 +00:00
Fixed: Tracked Download Cache Keeps Deleted Albums (#811)
* Fixed: Tracked Download Cache Deleted Albums * Add a test
This commit is contained in:
parent
2147c52695
commit
5defb69eb6
2 changed files with 76 additions and 1 deletions
|
@ -11,6 +11,7 @@
|
|||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.TrackedDownloads
|
||||
{
|
||||
|
@ -72,5 +73,54 @@ public void should_track_downloads_using_the_source_title_if_it_cannot_be_found_
|
|||
trackedDownload.RemoteAlbum.Albums.First().Id.Should().Be(4);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_unmap_tracked_download_if_album_deleted()
|
||||
{
|
||||
GivenDownloadHistory();
|
||||
|
||||
var remoteAlbum = new RemoteAlbum
|
||||
{
|
||||
Artist = new Artist() { Id = 5 },
|
||||
Albums = new List<Album> { new Album { Id = 4 } },
|
||||
ParsedAlbumInfo = new ParsedAlbumInfo()
|
||||
{
|
||||
AlbumTitle = "Audio Album",
|
||||
ArtistName = "Audio Artist"
|
||||
}
|
||||
};
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
||||
.Returns(remoteAlbum);
|
||||
|
||||
var client = new DownloadClientDefinition()
|
||||
{
|
||||
Id = 1,
|
||||
Protocol = DownloadProtocol.Torrent
|
||||
};
|
||||
|
||||
var item = new DownloadClientItem()
|
||||
{
|
||||
Title = "Audio Artist - Audio Album [2018 - FLAC]",
|
||||
DownloadId = "35238",
|
||||
};
|
||||
|
||||
// get a tracked download in place
|
||||
var trackedDownload = Subject.TrackDownload(client, item);
|
||||
Subject.GetTrackedDownloads().Should().HaveCount(1);
|
||||
|
||||
// simulate deletion - album no longer maps
|
||||
Mocker.GetMock<IParsingService>()
|
||||
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
||||
.Returns(default(RemoteAlbum));
|
||||
|
||||
// handle deletion event
|
||||
Subject.Handle(new AlbumDeletedEvent(remoteAlbum.Albums.First(), false));
|
||||
|
||||
// verify download has null remote album
|
||||
var trackedDownloads = Subject.GetTrackedDownloads();
|
||||
trackedDownloads.Should().HaveCount(1);
|
||||
trackedDownloads.First().RemoteAlbum.Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
|
||||
namespace NzbDrone.Core.Download.TrackedDownloads
|
||||
{
|
||||
public interface ITrackedDownloadService
|
||||
public interface ITrackedDownloadService : IHandle<AlbumDeletedEvent>
|
||||
{
|
||||
TrackedDownload Find(string downloadId);
|
||||
void StopTracking(string downloadId);
|
||||
|
@ -48,6 +49,24 @@ public TrackedDownload Find(string downloadId)
|
|||
return _cache.Find(downloadId);
|
||||
}
|
||||
|
||||
public void UpdateAlbumCache(int albumId)
|
||||
{
|
||||
var updateCacheItems = _cache.Values.Where(x => x.RemoteAlbum.Albums.Any(a => a.Id == albumId)).ToList();
|
||||
|
||||
foreach (var item in updateCacheItems)
|
||||
{
|
||||
var parsedAlbumInfo = Parser.Parser.ParseAlbumTitle(item.DownloadItem.Title);
|
||||
item.RemoteAlbum = null;
|
||||
|
||||
if (parsedAlbumInfo != null)
|
||||
{
|
||||
item.RemoteAlbum = _parsingService.Map(parsedAlbumInfo);
|
||||
}
|
||||
}
|
||||
|
||||
_eventAggregator.PublishEvent(new TrackedDownloadRefreshedEvent(GetTrackedDownloads()));
|
||||
}
|
||||
|
||||
public void StopTracking(string downloadId)
|
||||
{
|
||||
var trackedDownload = _cache.Find(downloadId);
|
||||
|
@ -224,5 +243,11 @@ private static TrackedDownloadStage GetStateFromHistory(NzbDrone.Core.History.Hi
|
|||
|
||||
return TrackedDownloadStage.Downloading;
|
||||
}
|
||||
|
||||
public void Handle(AlbumDeletedEvent message)
|
||||
{
|
||||
UpdateAlbumCache(message.Album.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue