Added: Movie files are now eager loaded. This should speed up the loading process a lot as well as RSS Sync and other tasks. It should also prevent some other bugs.

pull/2/head
Leonardo Galli 7 years ago
parent ecd25dddf1
commit 628c044c46

@ -93,12 +93,13 @@ namespace NzbDrone.Api.Movie
if (model == null) return null; if (model == null) return null;
long size = 0; long size = model.MovieFile?.Size ?? 0;
bool downloaded = false; bool downloaded = model.MovieFile != null;
MovieFileResource movieFile = null; MovieFileResource movieFile = model.MovieFile?.ToResource();
if(model.MovieFile != null)
/*if(model.MovieFile != null)
{ {
model.MovieFile.LazyLoad(); model.MovieFile.LazyLoad();
} }
@ -108,7 +109,7 @@ namespace NzbDrone.Api.Movie
size = model.MovieFile.Value.Size; size = model.MovieFile.Value.Size;
downloaded = true; downloaded = true;
movieFile = model.MovieFile.Value.ToResource(); movieFile = model.MovieFile.Value.ToResource();
} }*/
//model.AlternativeTitles.LazyLoad(); //model.AlternativeTitles.LazyLoad();

@ -143,8 +143,8 @@ namespace NzbDrone.Core.Datastore
Mapper.Entity<Movie>().RegisterModel("Movies") Mapper.Entity<Movie>().RegisterModel("Movies")
.Ignore(s => s.RootFolderPath) .Ignore(s => s.RootFolderPath)
.Relationship() .Relationship()
.HasOne(s => s.Profile, s => s.ProfileId) .HasOne(s => s.Profile, s => s.ProfileId);
.HasOne(m => m.MovieFile, m => m.MovieFileId); //.HasOne(m => m.MovieFile, m => m.MovieFileId);
Mapper.Entity<AlternativeTitle>().RegisterModel("AlternativeTitles") Mapper.Entity<AlternativeTitle>().RegisterModel("AlternativeTitles")
.For(t => t.Id) .For(t => t.Id)

@ -38,9 +38,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public virtual Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria) public virtual Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria)
{ {
if (subject.Movie.MovieFile.Value != null) if (subject.Movie.MovieFile != null)
{ {
if (!_qualityUpgradableSpecification.CutoffNotMet(subject.Movie.Profile, subject.Movie.MovieFile.Value.Quality, subject.ParsedMovieInfo.Quality)) if (!_qualityUpgradableSpecification.CutoffNotMet(subject.Movie.Profile, subject.Movie.MovieFile.Quality, subject.ParsedMovieInfo.Quality))
{ {
return Decision.Reject("Existing file meets cutoff: {0}", subject.Movie.Profile.Value.Cutoff); return Decision.Reject("Existing file meets cutoff: {0}", subject.Movie.Profile.Value.Cutoff);
} }

@ -66,11 +66,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
if (isPreferredProtocol && (subject.Movie.MovieFileId != 0 && subject.Movie.MovieFile != null) && (preferredCount > 0 || preferredWords == null)) if (isPreferredProtocol && (subject.Movie.MovieFileId != 0 && subject.Movie.MovieFile != null) && (preferredCount > 0 || preferredWords == null))
{ {
var upgradable = _qualityUpgradableSpecification.IsUpgradable(profile, subject.Movie.MovieFile.Value.Quality, subject.ParsedMovieInfo.Quality); var upgradable = _qualityUpgradableSpecification.IsUpgradable(profile, subject.Movie.MovieFile.Quality, subject.ParsedMovieInfo.Quality);
if (upgradable) if (upgradable)
{ {
var revisionUpgrade = _qualityUpgradableSpecification.IsRevisionUpgrade(subject.Movie.MovieFile.Value.Quality, subject.ParsedMovieInfo.Quality); var revisionUpgrade = _qualityUpgradableSpecification.IsRevisionUpgrade(subject.Movie.MovieFile.Quality, subject.ParsedMovieInfo.Quality);
if (revisionUpgrade) if (revisionUpgrade)
{ {

@ -57,12 +57,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
return Decision.Accept(); return Decision.Accept();
} }
if (subject.Movie.MovieFile.Value == null) if (subject.Movie.MovieFile == null)
{ {
return Decision.Accept(); return Decision.Accept();
} }
var file = subject.Movie.MovieFile.Value; var file = subject.Movie.MovieFile;
if (_qualityUpgradableSpecification.IsRevisionUpgrade(file.Quality, subject.ParsedMovieInfo.Quality)) if (_qualityUpgradableSpecification.IsRevisionUpgrade(file.Quality, subject.ParsedMovieInfo.Quality))
{ {

@ -35,12 +35,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public virtual Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria) public virtual Decision IsSatisfiedBy(RemoteMovie subject, SearchCriteriaBase searchCriteria)
{ {
if (subject.Movie.MovieFile.Value == null) if (subject.Movie.MovieFile == null)
{ {
return Decision.Accept(); return Decision.Accept();
} }
var file = subject.Movie.MovieFile.Value; var file = subject.Movie.MovieFile;
_logger.Debug("Comparing file quality with report. Existing file is {0}", file.Quality); _logger.Debug("Comparing file quality with report. Existing file is {0}", file.Quality);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Movie.Profile, file.Quality, subject.ParsedMovieInfo.Quality)) if (!_qualityUpgradableSpecification.IsUpgradable(subject.Movie.Profile, file.Quality, subject.ParsedMovieInfo.Quality))

@ -44,7 +44,7 @@ namespace NzbDrone.Core.MediaFiles
_logger.Trace("Upgrading existing movie file."); _logger.Trace("Upgrading existing movie file.");
var moveFileResult = new MovieFileMoveResult(); var moveFileResult = new MovieFileMoveResult();
var existingFile = localMovie.Movie.MovieFile.Value; var existingFile = localMovie.Movie.MovieFile;
if (existingFile != null) if (existingFile != null)
{ {

@ -224,9 +224,9 @@ namespace NzbDrone.Core.Organizer
AddReleaseDateTokens(tokenHandlers, movie.Year); AddReleaseDateTokens(tokenHandlers, movie.Year);
AddImdbIdTokens(tokenHandlers, movie.ImdbId); AddImdbIdTokens(tokenHandlers, movie.ImdbId);
if(movie.MovieFileId != 0) if(movie.MovieFile != null)
{ {
movieFile.LazyLoad();
AddQualityTokens(tokenHandlers, movie, movieFile); AddQualityTokens(tokenHandlers, movie, movieFile);
AddMediaInfoTokens(tokenHandlers, movieFile); AddMediaInfoTokens(tokenHandlers, movieFile);
AddMovieFileTokens(tokenHandlers, movieFile); AddMovieFileTokens(tokenHandlers, movieFile);
@ -361,9 +361,8 @@ namespace NzbDrone.Core.Organizer
AddReleaseDateTokens(tokenHandlers, movie.Year); AddReleaseDateTokens(tokenHandlers, movie.Year);
AddImdbIdTokens(tokenHandlers, movie.ImdbId); AddImdbIdTokens(tokenHandlers, movie.ImdbId);
if (movie.MovieFileId != 0) if (movie.MovieFile != null)
{ {
movieFile.LazyLoad();
AddQualityTokens(tokenHandlers, movie, movieFile); AddQualityTokens(tokenHandlers, movie, movieFile);
AddMediaInfoTokens(tokenHandlers, movieFile); AddMediaInfoTokens(tokenHandlers, movieFile);
AddMovieFileTokens(tokenHandlers, movieFile); AddMovieFileTokens(tokenHandlers, movieFile);

@ -51,7 +51,7 @@ namespace NzbDrone.Core.Tv
public LazyLoaded<Profile> Profile { get; set; } public LazyLoaded<Profile> Profile { get; set; }
public HashSet<int> Tags { get; set; } public HashSet<int> Tags { get; set; }
public AddMovieOptions AddOptions { get; set; } public AddMovieOptions AddOptions { get; set; }
public LazyLoaded<MovieFile> MovieFile { get; set; } public MovieFile MovieFile { get; set; }
public bool HasPreDBEntry { get; set; } public bool HasPreDBEntry { get; set; }
public int MovieFileId { get; set; } public int MovieFileId { get; set; }
//Get Loaded via a Join Query //Get Loaded via a Join Query

@ -297,6 +297,7 @@ namespace NzbDrone.Core.Tv
baseQuery = base.AddJoinQueries(baseQuery); baseQuery = base.AddJoinQueries(baseQuery);
baseQuery = baseQuery.Join<Movie, AlternativeTitle>(JoinType.Left, m => m.AlternativeTitles, baseQuery = baseQuery.Join<Movie, AlternativeTitle>(JoinType.Left, m => m.AlternativeTitles,
(m, t) => m.Id == t.MovieId); (m, t) => m.Id == t.MovieId);
baseQuery = baseQuery.Join<Movie, MovieFile>(JoinType.Left, m => m.MovieFile, (m, f) => m.Id == f.MovieId);
return baseQuery; return baseQuery;
} }

Loading…
Cancel
Save