From e805f614509b62eb7b2955d2a314fd1eb4e7d972 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 9 Jan 2023 22:08:20 -0600 Subject: [PATCH] Use Length/Count property instead of Count() method to prevent enumerating --- .editorconfig | 1 - .../Extras/Others/OtherExtraServiceFixture.cs | 4 ++-- .../Extras/Subtitles/SubtitleServiceFixture.cs | 12 ++++++------ .../EpisodeServiceTests/FindEpisodeByTitleFixture.cs | 2 +- .../Specifications/AcceptableSizeSpecification.cs | 2 +- .../Specifications/SeasonPackOnlySpecification.cs | 2 +- .../JsonConverters/SabnzbdQueueTimeConverter.cs | 2 +- .../Download/Pending/PendingReleaseService.cs | 4 ++-- .../Extras/Subtitles/SubtitleService.cs | 2 +- .../HealthCheck/Checks/RemovedSeriesCheck.cs | 2 +- .../TorrentRss/TorrentRssSettingsDetector.cs | 2 +- src/NzbDrone.Core/Jobs/TaskManager.cs | 2 +- .../MediaFiles/EpisodeImport/ImportDecisionMaker.cs | 2 +- .../EpisodeImport/Manual/ManualImportService.cs | 2 +- 14 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.editorconfig b/.editorconfig index 09580cb96..8a02d7e30 100644 --- a/.editorconfig +++ b/.editorconfig @@ -194,7 +194,6 @@ dotnet_diagnostic.CA1819.severity = suggestion dotnet_diagnostic.CA1822.severity = suggestion dotnet_diagnostic.CA1823.severity = suggestion dotnet_diagnostic.CA1824.severity = suggestion -dotnet_diagnostic.CA1829.severity = suggestion dotnet_diagnostic.CA1834.severity = suggestion dotnet_diagnostic.CA1839.severity = suggestion dotnet_diagnostic.CA1840.severity = suggestion diff --git a/src/NzbDrone.Core.Test/Extras/Others/OtherExtraServiceFixture.cs b/src/NzbDrone.Core.Test/Extras/Others/OtherExtraServiceFixture.cs index a79dd0f1f..d35470c64 100644 --- a/src/NzbDrone.Core.Test/Extras/Others/OtherExtraServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Extras/Others/OtherExtraServiceFixture.cs @@ -71,7 +71,7 @@ namespace NzbDrone.Core.Test.Extras.Others var results = Subject.ImportFiles(_localEpisode, _episodeFile, files, true).ToList(); - results.Count().Should().Be(1); + results.Count.Should().Be(1); results[0].RelativePath.AsOsAgnostic().PathEquals(Path.Combine("Season 1", expectedOutputPath).AsOsAgnostic()).Should().Be(true); } @@ -87,7 +87,7 @@ namespace NzbDrone.Core.Test.Extras.Others var results = Subject.ImportFiles(_localEpisode, _episodeFile, files, true).ToList(); - results.Count().Should().Be(1); + results.Count.Should().Be(1); } } } diff --git a/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs b/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs index bf788b38f..532736000 100644 --- a/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs @@ -74,7 +74,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles var results = Subject.ImportFiles(_localEpisode, _episodeFile, files, true).ToList(); - results.Count().Should().Be(0); + results.Count.Should().Be(0); } [Test] @@ -92,7 +92,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles var results = Subject.ImportFiles(_localEpisode, _episodeFile, files, true).ToList(); - results.Count().Should().Be(1); + results.Count.Should().Be(1); results[0].RelativePath.AsOsAgnostic().PathEquals(Path.Combine("Season 1", expectedOutputPath).AsOsAgnostic()).Should().Be(true); } @@ -118,7 +118,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles var results = Subject.ImportFiles(_localEpisode, _episodeFile, files, true).ToList(); - results.Count().Should().Be(expectedOutputs.Length); + results.Count.Should().Be(expectedOutputs.Length); for (int i = 0; i < expectedOutputs.Length; i++) { @@ -147,7 +147,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles var results = Subject.ImportFiles(_localEpisode, _episodeFile, files, true).ToList(); - results.Count().Should().Be(expectedOutputs.Length); + results.Count.Should().Be(expectedOutputs.Length); for (int i = 0; i < expectedOutputs.Length; i++) { @@ -178,7 +178,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles var results = Subject.ImportFiles(_localEpisode, _episodeFile, new List { subtitleFile }, true).ToList(); - results.Count().Should().Be(1); + results.Count.Should().Be(1); results[0].RelativePath.AsOsAgnostic().PathEquals(Path.Combine("Season 1", expectedOutputPath).AsOsAgnostic()).Should().Be(true); @@ -203,7 +203,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles var results = Subject.ImportFiles(_localEpisode, _episodeFile, new List { subtitleFile }, true).ToList(); - results.Count().Should().Be(0); + results.Count.Should().Be(0); } } } diff --git a/src/NzbDrone.Core.Test/TvTests/EpisodeServiceTests/FindEpisodeByTitleFixture.cs b/src/NzbDrone.Core.Test/TvTests/EpisodeServiceTests/FindEpisodeByTitleFixture.cs index 3cf97cce8..8b3447c81 100644 --- a/src/NzbDrone.Core.Test/TvTests/EpisodeServiceTests/FindEpisodeByTitleFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/EpisodeServiceTests/FindEpisodeByTitleFixture.cs @@ -24,7 +24,7 @@ namespace NzbDrone.Core.Test.TvTests.EpisodeServiceTests private void GivenEpisodesWithTitles(params string[] titles) { - for (int i = 0; i < titles.Count(); i++) + for (int i = 0; i < titles.Length; i++) { _episodes[i].Title = titles[i]; } diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs index 4e2367f99..de3a2a7dc 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/AcceptableSizeSpecification.cs @@ -109,7 +109,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications // Ensure that this is either the first episode // or is the last episode in a season that has 10 or more episodes - if (seasonEpisodes.First().Id == firstEpisode.Id || (seasonEpisodes.Count() >= 10 && seasonEpisodes.Last().Id == firstEpisode.Id)) + if (seasonEpisodes.First().Id == firstEpisode.Id || (seasonEpisodes.Count >= 10 && seasonEpisodes.Last().Id == firstEpisode.Id)) { _logger.Debug("Possible double episode, doubling allowed size."); maxSize = maxSize * 2; diff --git a/src/NzbDrone.Core/DecisionEngine/Specifications/SeasonPackOnlySpecification.cs b/src/NzbDrone.Core/DecisionEngine/Specifications/SeasonPackOnlySpecification.cs index 5a8f9a720..317fc721b 100644 --- a/src/NzbDrone.Core/DecisionEngine/Specifications/SeasonPackOnlySpecification.cs +++ b/src/NzbDrone.Core/DecisionEngine/Specifications/SeasonPackOnlySpecification.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications // test against episodes of the same season in the current search, and make sure they have an air date var subset = searchCriteria.Episodes.Where(e => e.AirDateUtc.HasValue && e.SeasonNumber == subject.Episodes.First().SeasonNumber).ToList(); - if (subset.Count() > 0 && subset.Max(e => e.AirDateUtc).Value.Before(DateTime.UtcNow - TimeSpan.FromDays(subject.Release.SeasonSearchMaximumSingleEpisodeAge))) + if (subset.Count > 0 && subset.Max(e => e.AirDateUtc).Value.Before(DateTime.UtcNow - TimeSpan.FromDays(subject.Release.SeasonSearchMaximumSingleEpisodeAge))) { _logger.Debug("Release {0}: last episode in this season aired more than {1} days ago, season pack required.", subject.Release.Title, subject.Release.SeasonSearchMaximumSingleEpisodeAge); return Decision.Reject("Last episode in this season aired more than {0} days ago, season pack required.", subject.Release.SeasonSearchMaximumSingleEpisodeAge); diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdQueueTimeConverter.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdQueueTimeConverter.cs index 10efa12b2..a94c7811a 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdQueueTimeConverter.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdQueueTimeConverter.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters { var split = reader.Value.ToString().Split(':').Select(int.Parse).ToArray(); - switch (split.Count()) + switch (split.Length) { case 4: return new TimeSpan((split[0] * 24) + split[1], split[2], split[3]); diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index b859e91ff..7f59e83fe 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -117,9 +117,9 @@ namespace NzbDrone.Core.Download.Pending _logger.Debug("The release {0} is already pending with reason {1}, not adding again", decision.RemoteEpisode, reason); } - if (matchingReports.Count() > 1) + if (matchingReports.Count > 1) { - _logger.Debug("The release {0} had {1} duplicate pending, removing duplicates.", decision.RemoteEpisode, matchingReports.Count() - 1); + _logger.Debug("The release {0} had {1} duplicate pending, removing duplicates.", decision.RemoteEpisode, matchingReports.Count - 1); foreach (var duplicate in matchingReports.Skip(1)) { diff --git a/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs b/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs index 4acbc9eb8..e929574a5 100644 --- a/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs +++ b/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs @@ -149,7 +149,7 @@ namespace NzbDrone.Core.Extras.Subtitles .Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file))) .ToList(); - if (videoFiles.Count() > 2) + if (videoFiles.Count > 2) { return importedFiles; } diff --git a/src/NzbDrone.Core/HealthCheck/Checks/RemovedSeriesCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/RemovedSeriesCheck.cs index cd8d4c4cb..36c1e7cca 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/RemovedSeriesCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/RemovedSeriesCheck.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.HealthCheck.Checks var seriesText = deletedSeries.Select(s => $"{s.Title} (tvdbid {s.TvdbId})").Join(", "); - if (deletedSeries.Count() == 1) + if (deletedSeries.Count == 1) { return new HealthCheck(GetType(), HealthCheckResult.Error, $"Series {seriesText} was removed from TheTVDB", "#series-removed-from-thetvdb"); } diff --git a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs index faeb40808..66bed891c 100644 --- a/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs +++ b/src/NzbDrone.Core/Indexers/TorrentRss/TorrentRssSettingsDetector.cs @@ -177,7 +177,7 @@ namespace NzbDrone.Core.Indexers.TorrentRss releases = ParseResponse(parser, response); ValidateReleases(releases, indexerSettings); - if (releases.Count(r => r.Size >= ValidSizeThreshold) > releases.Count() / 2) + if (releases.Count(r => r.Size >= ValidSizeThreshold) > releases.Length / 2) { if (releases.Any(r => r.Size < ValidSizeThreshold)) { diff --git a/src/NzbDrone.Core/Jobs/TaskManager.cs b/src/NzbDrone.Core/Jobs/TaskManager.cs index 1423a0281..85113b39b 100644 --- a/src/NzbDrone.Core/Jobs/TaskManager.cs +++ b/src/NzbDrone.Core/Jobs/TaskManager.cs @@ -136,7 +136,7 @@ namespace NzbDrone.Core.Jobs var currentTasks = _scheduledTaskRepository.All().ToList(); - _logger.Trace("Initializing jobs. Available: {0} Existing: {1}", defaultTasks.Count(), currentTasks.Count()); + _logger.Trace("Initializing jobs. Available: {0} Existing: {1}", defaultTasks.Count, currentTasks.Count); foreach (var job in currentTasks) { diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs index c499783f6..5c7d3b55a 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/ImportDecisionMaker.cs @@ -68,7 +68,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport { var newFiles = filterExistingFiles ? _mediaFileService.FilterExistingFiles(videoFiles.ToList(), series) : videoFiles.ToList(); - _logger.Debug("Analyzing {0}/{1} files.", newFiles.Count, videoFiles.Count()); + _logger.Debug("Analyzing {0}/{1} files.", newFiles.Count, videoFiles.Count); ParsedEpisodeInfo downloadClientItemInfo = null; diff --git a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs index f2d6ac8ed..66a8248c8 100644 --- a/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/EpisodeImport/Manual/ManualImportService.cs @@ -245,7 +245,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Manual // If the series is unknown for the directory and there are more than 100 files in the folder don't process the items before returning. var files = _diskScanService.FilterPaths(rootFolder, _diskScanService.GetVideoFiles(baseFolder, false)); - if (files.Count() > 100) + if (files.Count > 100) { _logger.Warn("Unable to determine series from folder name and found more than 100 files. Skipping parsing"); return ProcessDownloadDirectory(rootFolder, files);