From 10766dd227646bfa9eed528fd5ec121875770215 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 #2571 --- .../Books/Repositories/AuthorRepository.cs | 10 ++++++++++ src/NzbDrone.Core/Books/Services/AuthorService.cs | 6 ++++++ src/NzbDrone.Core/Tags/TagService.cs | 4 ++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs b/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs index cc741a0c4..f3c38e80d 100644 --- a/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs +++ b/src/NzbDrone.Core/Books/Repositories/AuthorRepository.cs @@ -13,6 +13,7 @@ namespace NzbDrone.Core.Books Author FindByName(string cleanName); Author FindById(string foreignAuthorId); Dictionary AllAuthorPaths(); + Dictionary> AllAuthorTags(); Author GetAuthorByMetadataId(int authorMetadataId); List GetAuthorsByMetadataId(IEnumerable authorMetadataId); } @@ -65,6 +66,15 @@ namespace NzbDrone.Core.Books } } + public Dictionary> AllAuthorTags() + { + using (var conn = _database.OpenConnection()) + { + var strSql = "SELECT \"Id\" AS \"Key\", \"Tags\" AS \"Value\" FROM \"Authors\" WHERE \"Tags\" IS NOT NULL"; + return conn.Query>>(strSql).ToDictionary(x => x.Key, x => x.Value); + } + } + public Author GetAuthorByMetadataId(int authorMetadataId) { return Query(s => s.AuthorMetadataId == authorMetadataId).SingleOrDefault(); diff --git a/src/NzbDrone.Core/Books/Services/AuthorService.cs b/src/NzbDrone.Core/Books/Services/AuthorService.cs index b0a5515b2..372ef218c 100644 --- a/src/NzbDrone.Core/Books/Services/AuthorService.cs +++ b/src/NzbDrone.Core/Books/Services/AuthorService.cs @@ -24,6 +24,7 @@ namespace NzbDrone.Core.Books List GetReportCandidates(string reportTitle); void DeleteAuthor(int authorId, bool deleteFiles, bool addImportListExclusion = false); List GetAllAuthors(); + Dictionary> GetAllAuthorTags(); List AllForTag(int tagId); Author UpdateAuthor(Author author); List UpdateAuthors(List authors, bool useExistingRelativeFolder); @@ -185,6 +186,11 @@ namespace NzbDrone.Core.Books return _cache.Get("GetAllAuthors", () => _authorRepository.All().ToList(), TimeSpan.FromSeconds(30)); } + public Dictionary> GetAllAuthorTags() + { + return _authorRepository.AllAuthorTags(); + } + public Dictionary AllAuthorPaths() { return _authorRepository.AllAuthorPaths(); diff --git a/src/NzbDrone.Core/Tags/TagService.cs b/src/NzbDrone.Core/Tags/TagService.cs index dbee84331..5fa50dfcc 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 authors = _authorService.GetAllAuthors(); + var authors = _authorService.GetAllAuthorTags(); var indexers = _indexerService.All(); var rootFolders = _rootFolderService.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(), - AuthorIds = authors.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), + AuthorIds = authors.Where(c => c.Value.Contains(tag.Id)).Select(c => c.Key).ToList(), IndexerIds = indexers.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), RootFolderIds = rootFolders.Where(c => c.DefaultTags.Contains(tag.Id)).Select(c => c.Id).ToList() });