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