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) ||
|
||||
drive.RootDirectory.IsParentPath(path))
|
||||
.OrderByDescending(drive => drive.RootDirectory.Length)
|
||||
.FirstOrDefault();
|
||||
.MaxBy(drive => drive.RootDirectory.Length);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
using NzbDrone.Core.Download.Aggregation;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Languages;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Parser;
|
||||
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 existingReports = episodeIds.SelectMany(v => alreadyPendingByEpisode[v] ?? Enumerable.Empty<PendingRelease>())
|
||||
var existingReports = episodeIds.SelectMany(v => alreadyPendingByEpisode[v])
|
||||
.Distinct().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)
|
||||
.Where(r => r.Episodes.Select(e => e.Id).Intersect(episodeIds).Any())
|
||||
.OrderByDescending(p => p.Release.AgeHours)
|
||||
.FirstOrDefault();
|
||||
.MaxBy(p => p.Release.AgeHours);
|
||||
}
|
||||
|
||||
private ILookup<int, PendingRelease> CreateEpisodeLookup(IEnumerable<PendingRelease> alreadyPending)
|
||||
|
@ -30,9 +30,7 @@ public HistoryRepository(IMainDatabase database, IEventAggregator eventAggregato
|
||||
|
||||
public EpisodeHistory MostRecentForEpisode(int episodeId)
|
||||
{
|
||||
return Query(h => h.EpisodeId == episodeId)
|
||||
.OrderByDescending(h => h.Date)
|
||||
.FirstOrDefault();
|
||||
return Query(h => h.EpisodeId == episodeId).MaxBy(h => h.Date);
|
||||
}
|
||||
|
||||
public List<EpisodeHistory> FindByEpisodeId(int episodeId)
|
||||
@ -44,9 +42,7 @@ public List<EpisodeHistory> FindByEpisodeId(int episodeId)
|
||||
|
||||
public EpisodeHistory MostRecentForDownloadId(string downloadId)
|
||||
{
|
||||
return Query(h => h.DownloadId == downloadId)
|
||||
.OrderByDescending(h => h.Date)
|
||||
.FirstOrDefault();
|
||||
return Query(h => h.DownloadId == downloadId).MaxBy(h => h.Date);
|
||||
}
|
||||
|
||||
public List<EpisodeHistory> FindByDownloadId(string downloadId)
|
||||
|
@ -186,9 +186,7 @@ public RootFolder Get(int id, bool timeout)
|
||||
|
||||
public string GetBestRootFolderPath(string path)
|
||||
{
|
||||
var possibleRootFolder = All().Where(r => r.Path.IsParentPath(path))
|
||||
.OrderByDescending(r => r.Path.Length)
|
||||
.FirstOrDefault();
|
||||
var possibleRootFolder = All().Where(r => r.Path.IsParentPath(path)).MaxBy(r => r.Path.Length);
|
||||
|
||||
if (possibleRootFolder == null)
|
||||
{
|
||||
|
@ -50,16 +50,11 @@ private SeriesStatistics MapSeriesStatistics(List<SeasonStatistics> seasonStatis
|
||||
ReleaseGroups = seasonStatistics.SelectMany(s => s.ReleaseGroups).Distinct().ToList()
|
||||
};
|
||||
|
||||
var nextAiring = seasonStatistics.Where(s => s.NextAiring != null)
|
||||
.OrderBy(s => s.NextAiring)
|
||||
.FirstOrDefault();
|
||||
var nextAiring = seasonStatistics.Where(s => s.NextAiring != null).MinBy(s => s.NextAiring);
|
||||
var previousAiring = seasonStatistics.Where(s => s.PreviousAiring != null).MaxBy(s => s.PreviousAiring);
|
||||
|
||||
var previousAiring = seasonStatistics.Where(s => s.PreviousAiring != null)
|
||||
.OrderBy(s => s.PreviousAiring)
|
||||
.LastOrDefault();
|
||||
|
||||
seriesStatistics.NextAiringString = nextAiring != null ? nextAiring.NextAiringString : null;
|
||||
seriesStatistics.PreviousAiringString = previousAiring != null ? previousAiring.PreviousAiringString : null;
|
||||
seriesStatistics.NextAiringString = nextAiring?.NextAiringString;
|
||||
seriesStatistics.PreviousAiringString = previousAiring?.PreviousAiringString;
|
||||
|
||||
return seriesStatistics;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public bool ShouldRefresh(Series series)
|
||||
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))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user