1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-27 02:09:59 +00:00

Simplify FindDownloadId to remove inaccessable code paths

This commit is contained in:
Qstick 2020-08-16 01:09:33 -04:00
parent 154092b921
commit ed76709b7f

View file

@ -97,6 +97,34 @@ public void UpdateMany(List<MovieHistory> toUpdate)
_historyRepository.UpdateMany(toUpdate);
}
public string FindDownloadId(MovieImportedEvent trackedDownload)
{
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedMovie.Path);
var movieId = trackedDownload.MovieInfo.Movie.Id;
var movieHistory = _historyRepository.FindDownloadHistory(movieId, trackedDownload.ImportedMovie.Quality);
var processedDownloadId = movieHistory
.Where(c => c.EventType != MovieHistoryEventType.Grabbed && c.DownloadId != null)
.Select(c => c.DownloadId);
var stillDownloading = movieHistory.Where(c => c.EventType == MovieHistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList();
string downloadId = null;
if (stillDownloading.Any())
{
if (stillDownloading.Count != 1)
{
return null;
}
downloadId = stillDownloading.Single().DownloadId;
}
return downloadId;
}
public void Handle(MovieGrabbedEvent message)
{
var history = new MovieHistory
@ -252,48 +280,6 @@ public void Handle(MoviesDeletedEvent message)
_historyRepository.DeleteForMovies(message.Movies.Select(m => m.Id).ToList());
}
public string FindDownloadId(MovieImportedEvent trackedDownload)
{
_logger.Debug("Trying to find downloadId for {0} from history", trackedDownload.ImportedMovie.Path);
var movieId = trackedDownload.MovieInfo.Movie.Id;
var movieHistory = _historyRepository.FindDownloadHistory(movieId, trackedDownload.ImportedMovie.Quality);
var processedDownloadId = movieHistory
.Where(c => c.EventType != MovieHistoryEventType.Grabbed && c.DownloadId != null)
.Select(c => c.DownloadId);
var stillDownloading = movieHistory.Where(c => c.EventType == MovieHistoryEventType.Grabbed && !processedDownloadId.Contains(c.DownloadId)).ToList();
string downloadId = null;
if (stillDownloading.Any())
{
//foreach (var matchingHistory in trackedDownload.EpisodeInfo.Episodes.Select(e => stillDownloading.Where(c => c.MovieId == e.Id).ToList()))
//foreach (var matchingHistory in stillDownloading.Where(c => c.MovieId == e.Id).ToList())
//{
if (stillDownloading.Count != 1)
{
return null;
}
var newDownloadId = stillDownloading.Single().DownloadId;
if (downloadId == null || downloadId == newDownloadId)
{
downloadId = newDownloadId;
}
else
{
return null;
}
//}
}
return downloadId;
}
public void Handle(DownloadFailedEvent message)
{
var history = new MovieHistory