mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-12 11:15:43 +02:00
Use MinBy and MaxBy instead of OrderBy + First
This commit is contained in:
parent
7fedfe7423
commit
6ea3d8c127
@ -450,12 +450,11 @@ public virtual IMount GetMount(string path)
|
|||||||
|
|
||||||
return mounts.Where(drive => drive.RootDirectory.PathEquals(path) ||
|
return mounts.Where(drive => drive.RootDirectory.PathEquals(path) ||
|
||||||
drive.RootDirectory.IsParentPath(path))
|
drive.RootDirectory.IsParentPath(path))
|
||||||
.OrderByDescending(drive => drive.RootDirectory.Length)
|
.MaxBy(drive => drive.RootDirectory.Length);
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Debug(ex, string.Format("Failed to get mount for path {0}", path));
|
Logger.Debug(ex, $"Failed to get mount for path {path}");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
using NzbDrone.Core.Download.Aggregation;
|
using NzbDrone.Core.Download.Aggregation;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.Jobs;
|
using NzbDrone.Core.Jobs;
|
||||||
using NzbDrone.Core.Languages;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Parser;
|
using NzbDrone.Core.Parser;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
@ -97,7 +96,7 @@ public void AddMany(List<Tuple<DownloadDecision, PendingReleaseReason>> decision
|
|||||||
|
|
||||||
var episodeIds = decision.RemoteEpisode.Episodes.Select(e => e.Id);
|
var episodeIds = decision.RemoteEpisode.Episodes.Select(e => e.Id);
|
||||||
|
|
||||||
var existingReports = episodeIds.SelectMany(v => alreadyPendingByEpisode[v] ?? Enumerable.Empty<PendingRelease>())
|
var existingReports = episodeIds.SelectMany(v => alreadyPendingByEpisode[v])
|
||||||
.Distinct().ToList();
|
.Distinct().ToList();
|
||||||
|
|
||||||
var matchingReports = existingReports.Where(MatchingReleasePredicate(decision.RemoteEpisode.Release)).ToList();
|
var matchingReports = existingReports.Where(MatchingReleasePredicate(decision.RemoteEpisode.Release)).ToList();
|
||||||
@ -243,8 +242,7 @@ public RemoteEpisode OldestPendingRelease(int seriesId, int[] episodeIds)
|
|||||||
|
|
||||||
return seriesReleases.Select(r => r.RemoteEpisode)
|
return seriesReleases.Select(r => r.RemoteEpisode)
|
||||||
.Where(r => r.Episodes.Select(e => e.Id).Intersect(episodeIds).Any())
|
.Where(r => r.Episodes.Select(e => e.Id).Intersect(episodeIds).Any())
|
||||||
.OrderByDescending(p => p.Release.AgeHours)
|
.MaxBy(p => p.Release.AgeHours);
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ILookup<int, PendingRelease> CreateEpisodeLookup(IEnumerable<PendingRelease> alreadyPending)
|
private ILookup<int, PendingRelease> CreateEpisodeLookup(IEnumerable<PendingRelease> alreadyPending)
|
||||||
|
@ -30,9 +30,7 @@ public HistoryRepository(IMainDatabase database, IEventAggregator eventAggregato
|
|||||||
|
|
||||||
public EpisodeHistory MostRecentForEpisode(int episodeId)
|
public EpisodeHistory MostRecentForEpisode(int episodeId)
|
||||||
{
|
{
|
||||||
return Query(h => h.EpisodeId == episodeId)
|
return Query(h => h.EpisodeId == episodeId).MaxBy(h => h.Date);
|
||||||
.OrderByDescending(h => h.Date)
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EpisodeHistory> FindByEpisodeId(int episodeId)
|
public List<EpisodeHistory> FindByEpisodeId(int episodeId)
|
||||||
@ -44,9 +42,7 @@ public List<EpisodeHistory> FindByEpisodeId(int episodeId)
|
|||||||
|
|
||||||
public EpisodeHistory MostRecentForDownloadId(string downloadId)
|
public EpisodeHistory MostRecentForDownloadId(string downloadId)
|
||||||
{
|
{
|
||||||
return Query(h => h.DownloadId == downloadId)
|
return Query(h => h.DownloadId == downloadId).MaxBy(h => h.Date);
|
||||||
.OrderByDescending(h => h.Date)
|
|
||||||
.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EpisodeHistory> FindByDownloadId(string downloadId)
|
public List<EpisodeHistory> FindByDownloadId(string downloadId)
|
||||||
|
@ -186,9 +186,7 @@ public RootFolder Get(int id, bool timeout)
|
|||||||
|
|
||||||
public string GetBestRootFolderPath(string path)
|
public string GetBestRootFolderPath(string path)
|
||||||
{
|
{
|
||||||
var possibleRootFolder = All().Where(r => r.Path.IsParentPath(path))
|
var possibleRootFolder = All().Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length);
|
||||||
.OrderByDescending(r => r.Path.Length)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (possibleRootFolder == null)
|
if (possibleRootFolder == null)
|
||||||
{
|
{
|
||||||
|
@ -50,16 +50,11 @@ private SeriesStatistics MapSeriesStatistics(List<SeasonStatistics> seasonStatis
|
|||||||
ReleaseGroups = seasonStatistics.SelectMany(s => s.ReleaseGroups).Distinct().ToList()
|
ReleaseGroups = seasonStatistics.SelectMany(s => s.ReleaseGroups).Distinct().ToList()
|
||||||
};
|
};
|
||||||
|
|
||||||
var nextAiring = seasonStatistics.Where(s => s.NextAiring != null)
|
var nextAiring = seasonStatistics.Where(s => s.NextAiring != null).MinBy(s => s.NextAiring);
|
||||||
.OrderBy(s => s.NextAiring)
|
var previousAiring = seasonStatistics.Where(s => s.PreviousAiring != null).MaxBy(s => s.PreviousAiring);
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
var previousAiring = seasonStatistics.Where(s => s.PreviousAiring != null)
|
seriesStatistics.NextAiringString = nextAiring?.NextAiringString;
|
||||||
.OrderBy(s => s.PreviousAiring)
|
seriesStatistics.PreviousAiringString = previousAiring?.PreviousAiringString;
|
||||||
.LastOrDefault();
|
|
||||||
|
|
||||||
seriesStatistics.NextAiringString = nextAiring != null ? nextAiring.NextAiringString : null;
|
|
||||||
seriesStatistics.PreviousAiringString = previousAiring != null ? previousAiring.PreviousAiringString : null;
|
|
||||||
|
|
||||||
return seriesStatistics;
|
return seriesStatistics;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public bool ShouldRefresh(Series series)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lastEpisode = _episodeService.GetEpisodeBySeries(series.Id).OrderByDescending(e => e.AirDateUtc).FirstOrDefault();
|
var lastEpisode = _episodeService.GetEpisodeBySeries(series.Id).MaxBy(e => e.AirDateUtc);
|
||||||
|
|
||||||
if (lastEpisode != null && lastEpisode.AirDateUtc > DateTime.UtcNow.AddDays(-30))
|
if (lastEpisode != null && lastEpisode.AirDateUtc > DateTime.UtcNow.AddDays(-30))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user