From 739a67263749b4fee3f071d85035e2bfd67168f8 Mon Sep 17 00:00:00 2001 From: Cody Kickertz Date: Sun, 21 Dec 2025 11:15:37 -0600 Subject: [PATCH] perf: replace List.Contains() with HashSet for O(1) lookups (#92) - ReleaseSearchService: wrap wantedLanguages in HashSet - FileNameBuilder: convert splitFilter array to HashSet - NewznabCategoryFieldOptionsConverter: use HashSet for category filters Addresses Issue #35 Co-authored-by: admin --- src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs | 3 ++- .../Indexers/Newznab/NewznabCategoryFieldOptionsConverter.cs | 4 ++-- src/NzbDrone.Core/Organizer/FileNameBuilder.cs | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs b/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs index a87cba171d..ed7cf6aee7 100644 --- a/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs @@ -8,6 +8,7 @@ using NzbDrone.Core.DecisionEngine; using NzbDrone.Core.Indexers; using NzbDrone.Core.IndexerSearch.Definitions; +using NzbDrone.Core.Languages; using NzbDrone.Core.Movies; using NzbDrone.Core.Movies.Translations; using NzbDrone.Core.Parser.Model; @@ -75,7 +76,7 @@ private TSpec Get(Movie movie, bool userInvokedSearch, bool interactiveSe InteractiveSearch = interactiveSearch }; - var wantedLanguages = _qualityProfileService.GetAcceptableLanguages(movie.QualityProfileId); + var wantedLanguages = new HashSet(_qualityProfileService.GetAcceptableLanguages(movie.QualityProfileId)); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId); var queryTranslations = new List diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabCategoryFieldOptionsConverter.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabCategoryFieldOptionsConverter.cs index 6d1095ca75..d1770273fe 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabCategoryFieldOptionsConverter.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabCategoryFieldOptionsConverter.cs @@ -9,10 +9,10 @@ public static class NewznabCategoryFieldOptionsConverter public static List> GetFieldSelectOptions(List categories) { // Categories not relevant for Radarr - var ignoreCategories = new[] { 1000, 3000, 4000, 6000, 7000 }; + var ignoreCategories = new HashSet { 1000, 3000, 4000, 6000, 7000 }; // And maybe relevant for specific users - var unimportantCategories = new[] { 0, 5000 }; + var unimportantCategories = new HashSet { 0, 5000 }; var result = new List>(); diff --git a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs index 8c1b395671..78ee1df901 100644 --- a/src/NzbDrone.Core/Organizer/FileNameBuilder.cs +++ b/src/NzbDrone.Core/Organizer/FileNameBuilder.cs @@ -451,12 +451,12 @@ private static string GetCustomFormatsToken(List customFormats, st { if (filter.StartsWith("-")) { - var splitFilter = filter.Substring(1).Split(','); + var splitFilter = new HashSet(filter.Substring(1).Split(',')); filteredTokens = tokens.Where(c => !splitFilter.Contains(c.Name)).ToList(); } else { - var splitFilter = filter.Split(','); + var splitFilter = new HashSet(filter.Split(',')); filteredTokens = tokens.Where(c => splitFilter.Contains(c.Name)).ToList(); } }