Use MinBy and MaxBy instead of OrderBy + First

Co-Authored-By: Stepan Goremykin <25577658+goremykin@users.noreply.github.com>
pull/8372/head
Qstick 2 years ago
parent e0ad573e7f
commit cc285fab45

@ -483,12 +483,11 @@ namespace NzbDrone.Common.Disk
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;
} }
} }

@ -239,8 +239,7 @@ namespace NzbDrone.Core.Download.Pending
var movieReleases = GetPendingReleases(movieId); var movieReleases = GetPendingReleases(movieId);
return movieReleases.Select(r => r.RemoteMovie) return movieReleases.Select(r => r.RemoteMovie)
.OrderByDescending(p => p.Release.AgeHours) .MaxBy(p => p.Release.AgeHours);
.FirstOrDefault();
} }
private List<PendingRelease> GetPendingReleases() private List<PendingRelease> GetPendingReleases()

@ -37,9 +37,7 @@ namespace NzbDrone.Core.History
public MovieHistory MostRecentForDownloadId(string downloadId) public MovieHistory MostRecentForDownloadId(string downloadId)
{ {
return FindByDownloadId(downloadId) return FindByDownloadId(downloadId).MaxBy(h => h.Date);
.OrderByDescending(h => h.Date)
.FirstOrDefault();
} }
public List<MovieHistory> FindByDownloadId(string downloadId) public List<MovieHistory> FindByDownloadId(string downloadId)
@ -90,9 +88,7 @@ namespace NzbDrone.Core.History
public MovieHistory MostRecentForMovie(int movieId) public MovieHistory MostRecentForMovie(int movieId)
{ {
return Query(x => x.MovieId == movieId) return Query(x => x.MovieId == movieId).MaxBy(h => h.Date);
.OrderByDescending(h => h.Date)
.FirstOrDefault();
} }
public List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType) public List<MovieHistory> Since(DateTime date, MovieHistoryEventType? eventType)

@ -182,9 +182,7 @@ namespace NzbDrone.Core.RootFolders
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)
{ {

Loading…
Cancel
Save