diff --git a/src/NzbDrone.Common/Disk/DiskProviderBase.cs b/src/NzbDrone.Common/Disk/DiskProviderBase.cs index 368dbe2b8..22077527c 100644 --- a/src/NzbDrone.Common/Disk/DiskProviderBase.cs +++ b/src/NzbDrone.Common/Disk/DiskProviderBase.cs @@ -473,12 +473,11 @@ namespace NzbDrone.Common.Disk 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; } } diff --git a/src/NzbDrone.Core/Books/Services/MonitorNewBookService.cs b/src/NzbDrone.Core/Books/Services/MonitorNewBookService.cs index 2e1325a78..6af2529ca 100644 --- a/src/NzbDrone.Core/Books/Services/MonitorNewBookService.cs +++ b/src/NzbDrone.Core/Books/Services/MonitorNewBookService.cs @@ -33,7 +33,7 @@ namespace NzbDrone.Core.Books if (monitorNewItems == NewItemMonitorTypes.New) { - var newest = existingBooks.OrderByDescending(x => x.ReleaseDate ?? DateTime.MinValue).FirstOrDefault()?.ReleaseDate ?? DateTime.MinValue; + var newest = existingBooks.MaxBy(x => x.ReleaseDate ?? DateTime.MinValue)?.ReleaseDate ?? DateTime.MinValue; return (addedBook.ReleaseDate ?? DateTime.MinValue) >= newest; } diff --git a/src/NzbDrone.Core/Books/Utilities/ShouldRefreshAuthor.cs b/src/NzbDrone.Core/Books/Utilities/ShouldRefreshAuthor.cs index ddf1537b6..7773fb29b 100644 --- a/src/NzbDrone.Core/Books/Utilities/ShouldRefreshAuthor.cs +++ b/src/NzbDrone.Core/Books/Utilities/ShouldRefreshAuthor.cs @@ -40,7 +40,7 @@ namespace NzbDrone.Core.Books return true; } - var lastBook = _bookService.GetBooksByAuthor(author.Id).OrderByDescending(e => e.ReleaseDate).FirstOrDefault(); + var lastBook = _bookService.GetBooksByAuthor(author.Id).MaxBy(e => e.ReleaseDate); if (lastBook != null && lastBook.ReleaseDate > DateTime.UtcNow.AddDays(-30)) { diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index d678eb8f2..65d0fa452 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -96,7 +96,7 @@ namespace NzbDrone.Core.Download.Pending var bookIds = decision.RemoteBook.Books.Select(e => e.Id); - var existingReports = bookIds.SelectMany(v => alreadyPendingByBook[v] ?? Enumerable.Empty()) + var existingReports = bookIds.SelectMany(v => alreadyPendingByBook[v]) .Distinct().ToList(); var matchingReports = existingReports.Where(MatchingReleasePredicate(decision.RemoteBook.Release)).ToList(); @@ -239,8 +239,7 @@ namespace NzbDrone.Core.Download.Pending return authorReleases.Select(r => r.RemoteBook) .Where(r => r.Books.Select(e => e.Id).Intersect(bookIds).Any()) - .OrderByDescending(p => p.Release.AgeHours) - .FirstOrDefault(); + .MaxBy(p => p.Release.AgeHours); } private ILookup CreateBookLookup(IEnumerable alreadyPending) diff --git a/src/NzbDrone.Core/History/HistoryRepository.cs b/src/NzbDrone.Core/History/HistoryRepository.cs index 4fbf21622..28e704837 100644 --- a/src/NzbDrone.Core/History/HistoryRepository.cs +++ b/src/NzbDrone.Core/History/HistoryRepository.cs @@ -29,16 +29,12 @@ namespace NzbDrone.Core.History public EntityHistory MostRecentForBook(int bookId) { - return Query(h => h.BookId == bookId) - .OrderByDescending(h => h.Date) - .FirstOrDefault(); + return Query(h => h.BookId == bookId).MaxBy(h => h.Date); } public EntityHistory 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 FindByDownloadId(string downloadId) diff --git a/src/NzbDrone.Core/MetadataSource/BookInfo/BookInfoProxy.cs b/src/NzbDrone.Core/MetadataSource/BookInfo/BookInfoProxy.cs index 3f024a4f9..1d0d127fd 100644 --- a/src/NzbDrone.Core/MetadataSource/BookInfo/BookInfoProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/BookInfo/BookInfoProxy.cs @@ -881,7 +881,7 @@ namespace NzbDrone.Core.MetadataSource.BookInfo book.Editions = resource.Books.Select(x => MapEdition(x)).ToList(); // monitor the most popular release - var mostPopular = book.Editions.Value.OrderByDescending(x => x.Ratings.Popularity).FirstOrDefault(); + var mostPopular = book.Editions.Value.MaxBy(x => x.Ratings.Popularity); if (mostPopular != null) { mostPopular.Monitored = true; diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 1ab06bef0..e69c1c06d 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -153,8 +153,7 @@ namespace NzbDrone.Core.RootFolders public RootFolder GetBestRootFolder(string path, List allRootFolders) { return allRootFolders.Where(r => PathEqualityComparer.Instance.Equals(r.Path, path) || r.Path.IsParentPath(path)) - .OrderByDescending(r => r.Path.Length) - .FirstOrDefault(); + .MaxBy(r => r.Path.Length); } public string GetBestRootFolderPath(string path)