mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 03:52:33 +02:00
Revert "Revert "Use async api calls for Refresh and NetImportSync""
This reverts commit 250cc09239
.
This commit is contained in:
parent
250cc09239
commit
0080e6b685
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@ -32,15 +33,15 @@ public void Setup()
|
||||
.Returns(_movie);
|
||||
|
||||
Mocker.GetMock<IProvideMovieInfo>()
|
||||
.Setup(s => s.GetMovieInfo(It.IsAny<int>()))
|
||||
.Callback<int>((i) => { throw new MovieNotFoundException(i); });
|
||||
.Setup(s => s.GetMovieInfoAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new MovieNotFoundException(1));
|
||||
}
|
||||
|
||||
private void GivenNewMovieInfo(Movie movie)
|
||||
{
|
||||
Mocker.GetMock<IProvideMovieInfo>()
|
||||
.Setup(s => s.GetMovieInfo(_movie.TmdbId))
|
||||
.Returns(new Tuple<Movie, List<Credit>>(movie, new List<Credit>()));
|
||||
.Setup(s => s.GetMovieInfoAsync(_movie.TmdbId))
|
||||
.ReturnsAsync(new Tuple<Movie, List<Credit>>(movie, new List<Credit>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -68,8 +68,8 @@ public void Setup()
|
||||
.Returns(false);
|
||||
|
||||
Mocker.GetMock<ISearchForNewMovie>()
|
||||
.Setup(v => v.MapMovieToTmdbMovie(It.IsAny<Movie>()))
|
||||
.Returns((Movie movie) => movie);
|
||||
.Setup(v => v.MapMovieToTmdbMovieAsync(It.IsAny<Movie>()))
|
||||
.ReturnsAsync((Movie movie) => movie);
|
||||
|
||||
Mocker.GetMock<IMovieService>()
|
||||
.Setup(v => v.MovieExists(It.IsAny<Movie>()))
|
||||
|
@ -2,6 +2,7 @@
|
||||
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;
|
||||
@ -52,7 +53,7 @@ public RefreshMovieService(IProvideMovieInfo movieInfo,
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private void RefreshMovieInfo(Movie movie)
|
||||
private void RefreshMovieInfo(Movie movie, Task<Tuple<Movie, List<Credit>>> dataTask)
|
||||
{
|
||||
_logger.ProgressInfo("Updating Info for {0}", movie.Title);
|
||||
|
||||
@ -61,7 +62,7 @@ private void RefreshMovieInfo(Movie movie)
|
||||
|
||||
try
|
||||
{
|
||||
var tuple = _movieInfo.GetMovieInfo(movie.TmdbId);
|
||||
var tuple = dataTask.GetAwaiter().GetResult();
|
||||
movieInfo = tuple.Item1;
|
||||
credits = tuple.Item2;
|
||||
}
|
||||
@ -172,10 +173,11 @@ public void Execute(RefreshMovieCommand message)
|
||||
if (message.MovieId.HasValue)
|
||||
{
|
||||
var movie = _movieService.GetMovie(message.MovieId.Value);
|
||||
var movieData = _movieInfo.GetMovieInfoAsync(movie.TmdbId);
|
||||
|
||||
try
|
||||
{
|
||||
RefreshMovieInfo(movie);
|
||||
RefreshMovieInfo(movie, movieData);
|
||||
RescanMovie(movie, isNew, trigger);
|
||||
}
|
||||
catch (MovieNotFoundException)
|
||||
@ -200,31 +202,44 @@ public void Execute(RefreshMovieCommand message)
|
||||
updatedTMDBMovies = _movieInfo.GetChangedMovies(message.LastStartTime.Value);
|
||||
}
|
||||
|
||||
foreach (var movie in allMovie)
|
||||
{
|
||||
if ((updatedTMDBMovies.Count == 0 && _checkIfMovieShouldBeRefreshed.ShouldRefresh(movie)) || updatedTMDBMovies.Contains(movie.TmdbId) || message.Trigger == CommandTrigger.Manual)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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);
|
||||
|
||||
RescanMovie(movie, false, trigger);
|
||||
}
|
||||
else
|
||||
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)
|
||||
{
|
||||
var finishedTask = Task.WhenAny(tasks).GetAwaiter().GetResult();
|
||||
tasks.Remove(finishedTask);
|
||||
|
||||
var movie = toRefresh[finishedTask];
|
||||
|
||||
try
|
||||
{
|
||||
_logger.Info("Skipping refresh of movie: {0}", movie.Title);
|
||||
RescanMovie(movie, false, trigger);
|
||||
RefreshMovieInfo(movie, finishedTask);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
@ -121,12 +122,17 @@ public void Execute(NetImportSyncCommand message)
|
||||
_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<string>();
|
||||
var moviesToAdd = new List<Movie>();
|
||||
|
||||
foreach (var movie in listedMovies)
|
||||
while (tasks.Count > 0)
|
||||
{
|
||||
var mapped = _movieSearch.MapMovieToTmdbMovie(movie);
|
||||
var finishedTask = Task.WhenAny(tasks).GetAwaiter().GetResult();
|
||||
tasks.Remove(finishedTask);
|
||||
|
||||
var mapped = finishedTask.GetAwaiter().GetResult();
|
||||
|
||||
if (mapped != null && mapped.TmdbId > 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user