diff --git a/src/NzbDrone.Core.Test/MovieTests/RefreshMovieServiceFixture.cs b/src/NzbDrone.Core.Test/MovieTests/RefreshMovieServiceFixture.cs index 893456650..5564eb096 100644 --- a/src/NzbDrone.Core.Test/MovieTests/RefreshMovieServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MovieTests/RefreshMovieServiceFixture.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using FizzWare.NBuilder; using Moq; using NUnit.Framework; @@ -33,15 +32,15 @@ namespace NzbDrone.Core.Test.MovieTests .Returns(_movie); Mocker.GetMock() - .Setup(s => s.GetMovieInfoAsync(It.IsAny())) - .ThrowsAsync(new MovieNotFoundException(1)); + .Setup(s => s.GetMovieInfo(It.IsAny())) + .Callback((i) => { throw new MovieNotFoundException(i); }); } private void GivenNewMovieInfo(Movie movie) { Mocker.GetMock() - .Setup(s => s.GetMovieInfoAsync(_movie.TmdbId)) - .ReturnsAsync(new Tuple>(movie, new List())); + .Setup(s => s.GetMovieInfo(_movie.TmdbId)) + .Returns(new Tuple>(movie, new List())); } [Test] diff --git a/src/NzbDrone.Core.Test/NetImport/NetImportSearchServiceFixture.cs b/src/NzbDrone.Core.Test/NetImport/NetImportSearchServiceFixture.cs index 79b40b865..441bf6e5f 100644 --- a/src/NzbDrone.Core.Test/NetImport/NetImportSearchServiceFixture.cs +++ b/src/NzbDrone.Core.Test/NetImport/NetImportSearchServiceFixture.cs @@ -68,8 +68,8 @@ namespace NzbDrone.Core.Test.NetImport .Returns(false); Mocker.GetMock() - .Setup(v => v.MapMovieToTmdbMovieAsync(It.IsAny())) - .ReturnsAsync((Movie movie) => movie); + .Setup(v => v.MapMovieToTmdbMovie(It.IsAny())) + .Returns((Movie movie) => movie); Mocker.GetMock() .Setup(v => v.MovieExists(It.IsAny())) diff --git a/src/NzbDrone.Core/Movies/RefreshMovieService.cs b/src/NzbDrone.Core/Movies/RefreshMovieService.cs index 07861a4c6..4f1f1d31a 100644 --- a/src/NzbDrone.Core/Movies/RefreshMovieService.cs +++ b/src/NzbDrone.Core/Movies/RefreshMovieService.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Threading.Tasks; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Common.Instrumentation.Extensions; @@ -53,7 +52,7 @@ namespace NzbDrone.Core.Movies _logger = logger; } - private void RefreshMovieInfo(Movie movie, Task>> dataTask) + private void RefreshMovieInfo(Movie movie) { _logger.ProgressInfo("Updating Info for {0}", movie.Title); @@ -62,7 +61,7 @@ namespace NzbDrone.Core.Movies try { - var tuple = dataTask.GetAwaiter().GetResult(); + var tuple = _movieInfo.GetMovieInfo(movie.TmdbId); movieInfo = tuple.Item1; credits = tuple.Item2; } @@ -173,11 +172,10 @@ namespace NzbDrone.Core.Movies if (message.MovieId.HasValue) { var movie = _movieService.GetMovie(message.MovieId.Value); - var movieData = _movieInfo.GetMovieInfoAsync(movie.TmdbId); try { - RefreshMovieInfo(movie, movieData); + RefreshMovieInfo(movie); RescanMovie(movie, isNew, trigger); } catch (MovieNotFoundException) @@ -202,44 +200,31 @@ namespace NzbDrone.Core.Movies updatedTMDBMovies = _movieInfo.GetChangedMovies(message.LastStartTime.Value); } - var toRefresh = allMovie - .Where(movie => (updatedTMDBMovies.Count == 0 && _checkIfMovieShouldBeRefreshed.ShouldRefresh(movie)) || - updatedTMDBMovies.Contains(movie.TmdbId) || - message.Trigger == CommandTrigger.Manual) - .ToDictionary(x => _movieInfo.GetMovieInfoAsync(x.TmdbId), x => x); - - var tasks = toRefresh.Keys.ToList(); - - var skipped = allMovie.Except(toRefresh.Values); - - foreach (var movie in skipped) - { - _logger.Info("Skipping refresh of movie: {0}", movie.Title); - RescanMovie(movie, false, trigger); - } - - while (tasks.Count > 0) + foreach (var movie in allMovie) { - var finishedTask = Task.WhenAny(tasks).GetAwaiter().GetResult(); - tasks.Remove(finishedTask); - - var movie = toRefresh[finishedTask]; - - try + if ((updatedTMDBMovies.Count == 0 && _checkIfMovieShouldBeRefreshed.ShouldRefresh(movie)) || updatedTMDBMovies.Contains(movie.TmdbId) || message.Trigger == CommandTrigger.Manual) { - RefreshMovieInfo(movie, finishedTask); + try + { + RefreshMovieInfo(movie); + } + catch (MovieNotFoundException) + { + _logger.Error("Movie '{0}' (imdbid {1}) was not found, it may have been removed from The Movie Database.", movie.Title, movie.ImdbId); + continue; + } + catch (Exception e) + { + _logger.Error(e, "Couldn't refresh info for {0}", movie); + } + + RescanMovie(movie, false, trigger); } - catch (MovieNotFoundException) + else { - _logger.Error("Movie '{0}' (imdbid {1}) was not found, it may have been removed from The Movie Database.", movie.Title, movie.ImdbId); - continue; + _logger.Info("Skipping refresh of movie: {0}", movie.Title); + RescanMovie(movie, false, trigger); } - catch (Exception e) - { - _logger.Error(e, "Couldn't refresh info for {0}", movie); - } - - RescanMovie(movie, false, trigger); } } } diff --git a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs index ee1166609..baa995d9b 100644 --- a/src/NzbDrone.Core/NetImport/NetImportSearchService.cs +++ b/src/NzbDrone.Core/NetImport/NetImportSearchService.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Core.Configuration; @@ -122,17 +121,12 @@ namespace NzbDrone.Core.NetImport _logger.Info($"Found {listedMovies.Count()} movies on your auto enabled lists not in your library"); } - var tasks = listedMovies.Select(x => _movieSearch.MapMovieToTmdbMovieAsync(x)).ToList(); - var importExclusions = new List(); var moviesToAdd = new List(); - while (tasks.Count > 0) + foreach (var movie in listedMovies) { - var finishedTask = Task.WhenAny(tasks).GetAwaiter().GetResult(); - tasks.Remove(finishedTask); - - var mapped = finishedTask.GetAwaiter().GetResult(); + var mapped = _movieSearch.MapMovieToTmdbMovie(movie); if (mapped != null && mapped.TmdbId > 0) {