diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2026-01-31 19:19:26 +0100 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2026-01-31 19:22:04 +0100 |
| commit | 2789532aa88ccc899ff8497537642e1d78b31ef5 (patch) | |
| tree | bc50cc8b536c9487ddaa773f5a411fc2ddd17ac8 /Emby.Server.Implementations/Library/Validators/GenresValidator.cs | |
| parent | 694db80d4c8e83ff381af56d2a3dde29e0855c3d (diff) | |
Optimize Validator and Filter Performance
Diffstat (limited to 'Emby.Server.Implementations/Library/Validators/GenresValidator.cs')
| -rw-r--r-- | Emby.Server.Implementations/Library/Validators/GenresValidator.cs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/Library/Validators/GenresValidator.cs b/Emby.Server.Implementations/Library/Validators/GenresValidator.cs index 09ede8bb8d..badd6f1183 100644 --- a/Emby.Server.Implementations/Library/Validators/GenresValidator.cs +++ b/Emby.Server.Implementations/Library/Validators/GenresValidator.cs @@ -54,6 +54,13 @@ public class GenresValidator IncludeItemTypes = [BaseItemKind.Genre] }).ToHashSet(); + var existingGenres = _libraryManager.GetItemList(new InternalItemsQuery + { + IncludeItemTypes = [BaseItemKind.Genre] + }).Cast<Genre>() + .GroupBy(g => g.Name, StringComparer.OrdinalIgnoreCase) + .ToDictionary(g => g.Key, g => g.First(), StringComparer.OrdinalIgnoreCase); + var numComplete = 0; var count = names.Count; var refreshed = 0; @@ -62,7 +69,15 @@ public class GenresValidator { try { - var item = _libraryManager.GetGenre(name); + Genre? item = null; + if (existingGenres.TryGetValue(name, out var existingGenre)) + { + item = existingGenre; + } + + // Fall back to GetGenre if not found (creates new item if needed) + item ??= _libraryManager.GetGenre(name); + if (!existingGenreIds.Contains(item.Id)) { await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); |
