Fixed: Lists are fetched much more efficiently. (Up to 40x loading time improvement with large lists!)

pull/1782/head
Leonardo Galli 7 years ago
parent fb4f510909
commit 964c18b236

@ -9,7 +9,7 @@ namespace NzbDrone.Api.NetImport
{
public NetImportModule(NetImportFactory netImportFactory) : base(netImportFactory, "netimport")
{
PostValidator.RuleFor(c => c.RootFolderPath).NotNull();
PostValidator.RuleFor(c => c.RootFolderPath).IsValidPath();
PostValidator.RuleFor(c => c.MinimumAvailability).NotNull();
PostValidator.RuleFor(c => c.ProfileId).NotNull();
}

@ -63,7 +63,7 @@ namespace NzbDrone.Core.NetImport
{
var movies = MovieListSearch(listId, onlyEnableAuto);
return movies.Where(x => !_movieService.MovieExists(x)).ToList();
return _movieService.FilterExistingMovies(movies);
}
public List<Movie> MovieListSearch(int listId, bool onlyEnableAuto = false)

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -39,6 +40,7 @@ namespace NzbDrone.Core.Tv
List<Movie> GetAllMovies();
Movie UpdateMovie(Movie movie);
List<Movie> UpdateMovie(List<Movie> movie);
List<Movie> FilterExistingMovies(List<Movie> movies);
bool MoviePathExists(string folder);
void RemoveAddOptions(Movie movie);
List<Movie> MoviesWithFiles(int movieId);
@ -444,5 +446,21 @@ namespace NzbDrone.Core.Tv
return false;
}
public List<Movie> FilterExistingMovies(List<Movie> movies)
{
var allMovies = GetAllMovies();
var withTmdbid = movies.Where(m => m.TmdbId != 0).ToList();
var withoutTmdbid = movies.Where(m => m.TmdbId == 0).ToList();
var withImdbid = withoutTmdbid.Where(m => m.ImdbId.IsNotNullOrWhiteSpace());
var rest = withoutTmdbid.Where(m => m.ImdbId.IsNullOrWhiteSpace());
var ret = withTmdbid.ExceptBy(m => m.TmdbId, allMovies, m => m.TmdbId, EqualityComparer<int>.Default)
.Union(withImdbid.ExceptBy(m => m.ImdbId, allMovies, m => m.ImdbId, EqualityComparer<string>.Default))
.Union(rest.ExceptBy(m => m.Title.CleanSeriesTitle(), allMovies, m => m.CleanTitle, EqualityComparer<string>.Default)).ToList();
return ret;
}
}
}

Loading…
Cancel
Save