From 1eb5f2dd492226e570ff8c9a23757a19f37d35d2 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 27 May 2023 17:58:56 -0500 Subject: [PATCH] Faster tag view in UI for large libraries (cherry picked from commit b050e1d2eb3bff9e28e7a1545d121be091789308) Closes #3762 --- .../Music/Repositories/ArtistRepository.cs | 10 ++++++++++ src/NzbDrone.Core/Music/Services/ArtistService.cs | 6 ++++++ src/NzbDrone.Core/Tags/TagService.cs | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs b/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs index 3e5d73765..214c0bf0a 100644 --- a/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs +++ b/src/NzbDrone.Core/Music/Repositories/ArtistRepository.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Core.Music Artist FindByName(string cleanName); Artist FindById(string foreignArtistId); Dictionary AllArtistPaths(); + Dictionary> AllArtistsTags(); Artist GetArtistByMetadataId(int artistMetadataId); List GetArtistByMetadataId(IEnumerable artistMetadataId); } @@ -79,6 +80,15 @@ namespace NzbDrone.Core.Music } } + public Dictionary> AllArtistsTags() + { + using (var conn = _database.OpenConnection()) + { + var strSql = "SELECT \"Id\" AS \"Key\", \"Tags\" AS \"Value\" FROM \"Artists\" WHERE \"Tags\" IS NOT NULL"; + return conn.Query>>(strSql).ToDictionary(x => x.Key, x => x.Value); + } + } + public List GetArtistByMetadataId(IEnumerable artistMetadataIds) { return Query(s => artistMetadataIds.Contains(s.ArtistMetadataId)); diff --git a/src/NzbDrone.Core/Music/Services/ArtistService.cs b/src/NzbDrone.Core/Music/Services/ArtistService.cs index 2a39254b5..8b44ce4d5 100644 --- a/src/NzbDrone.Core/Music/Services/ArtistService.cs +++ b/src/NzbDrone.Core/Music/Services/ArtistService.cs @@ -24,6 +24,7 @@ namespace NzbDrone.Core.Music void DeleteArtist(int artistId, bool deleteFiles, bool addImportListExclusion = false); void DeleteArtists(List artistIds, bool deleteFiles, bool addImportListExclusion = false); List GetAllArtists(); + Dictionary> GetAllArtistsTags(); List AllForTag(int tagId); Artist UpdateArtist(Artist artist, bool publishUpdatedEvent = true); List UpdateArtists(List artist, bool useExistingRelativeFolder); @@ -189,6 +190,11 @@ namespace NzbDrone.Core.Music return _artistRepository.AllArtistPaths(); } + public Dictionary> GetAllArtistsTags() + { + return _artistRepository.AllArtistsTags(); + } + public List AllForTag(int tagId) { return GetAllArtists().Where(s => s.Tags.Contains(tagId)) diff --git a/src/NzbDrone.Core/Tags/TagService.cs b/src/NzbDrone.Core/Tags/TagService.cs index 328e3f251..1ff330b68 100644 --- a/src/NzbDrone.Core/Tags/TagService.cs +++ b/src/NzbDrone.Core/Tags/TagService.cs @@ -106,7 +106,7 @@ namespace NzbDrone.Core.Tags var importLists = _importListFactory.All(); var notifications = _notificationFactory.All(); var restrictions = _releaseProfileService.All(); - var artists = _artistService.GetAllArtists(); + var artists = _artistService.GetAllArtistsTags(); var rootFolders = _rootFolderService.All(); var indexers = _indexerService.All(); @@ -122,7 +122,7 @@ namespace NzbDrone.Core.Tags ImportListIds = importLists.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), NotificationIds = notifications.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), RestrictionIds = restrictions.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), - ArtistIds = artists.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), + ArtistIds = artists.Where(c => c.Value.Contains(tag.Id)).Select(c => c.Key).ToList(), RootFolderIds = rootFolders.Where(c => c.DefaultTags.Contains(tag.Id)).Select(c => c.Id).ToList(), IndexerIds = indexers.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList() });