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

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

@ -38,9 +38,9 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
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);
}

@ -39,20 +39,20 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
var profile = subject.Movie.Profile.Value;
var delayProfile = _delayProfileService.BestForTags(subject.Movie.Tags);
var delay = delayProfile.GetProtocolDelay(subject.Release.DownloadProtocol);
var isPreferredProtocol = subject.Release.DownloadProtocol == delayProfile.PreferredProtocol;
// Preferred word count
var title = subject.Release.Title;
var preferredWords = subject.Movie.Profile.Value.PreferredTags;
var preferredCount = 0;
if (preferredWords == null)
{
preferredCount = 1;
var isPreferredProtocol = subject.Release.DownloadProtocol == delayProfile.PreferredProtocol;
// Preferred word count
var title = subject.Release.Title;
var preferredWords = subject.Movie.Profile.Value.PreferredTags;
var preferredCount = 0;
if (preferredWords == null)
{
preferredCount = 1;
_logger.Debug("Preferred words is null, setting preffered count to 1.");
}
else
{
}
else
{
preferredCount = preferredWords.AsEnumerable().Count(w => title.ToLower().Contains(w.ToLower()));
}
@ -66,11 +66,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
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)
{
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)
{
@ -83,7 +83,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
// If quality meets or exceeds the best allowed quality in the profile accept it immediately
var bestQualityInProfile = new QualityModel(profile.LastAllowedQuality());
var isBestInProfile = comparer.Compare(subject.ParsedMovieInfo.Quality, bestQualityInProfile) >= 0;
var isBestInProfile = comparer.Compare(subject.ParsedMovieInfo.Quality, bestQualityInProfile) >= 0;
if (isBestInProfile && isPreferredProtocol && (preferredCount > 0 || preferredWords == null))
{

@ -57,12 +57,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
return Decision.Accept();
}
if (subject.Movie.MovieFile.Value == null)
if (subject.Movie.MovieFile == null)
{
return Decision.Accept();
}
var file = subject.Movie.MovieFile.Value;
var file = subject.Movie.MovieFile;
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)
{
if (subject.Movie.MovieFile.Value == null)
if (subject.Movie.MovieFile == null)
{
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);
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.");
var moveFileResult = new MovieFileMoveResult();
var existingFile = localMovie.Movie.MovieFile.Value;
var existingFile = localMovie.Movie.MovieFile;
if (existingFile != null)
{

@ -224,9 +224,9 @@ namespace NzbDrone.Core.Organizer
AddReleaseDateTokens(tokenHandlers, movie.Year);
AddImdbIdTokens(tokenHandlers, movie.ImdbId);
if(movie.MovieFileId != 0)
if(movie.MovieFile != null)
{
movieFile.LazyLoad();
AddQualityTokens(tokenHandlers, movie, movieFile);
AddMediaInfoTokens(tokenHandlers, movieFile);
AddMovieFileTokens(tokenHandlers, movieFile);
@ -361,18 +361,17 @@ namespace NzbDrone.Core.Organizer
AddReleaseDateTokens(tokenHandlers, movie.Year);
AddImdbIdTokens(tokenHandlers, movie.ImdbId);
if (movie.MovieFileId != 0)
if (movie.MovieFile != null)
{
movieFile.LazyLoad();
AddQualityTokens(tokenHandlers, movie, movieFile);
AddMediaInfoTokens(tokenHandlers, movieFile);
AddMovieFileTokens(tokenHandlers, movieFile);
AddTagsTokens(tokenHandlers, movieFile);
}
else
else
{
AddMovieFileTokens(tokenHandlers, new MovieFile { SceneName = $"{movie.Title} {movie.Year}", RelativePath = $"{movie.Title} {movie.Year}"});
}
}
return CleanFolderName(ReplaceTokens(namingConfig.MovieFolderFormat, tokenHandlers, namingConfig));
}

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

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

Loading…
Cancel
Save