Faster tag view in UI for large libraries

(cherry picked from commit b050e1d2eb3bff9e28e7a1545d121be091789308)

Closes #2571
pull/2573/head
Qstick 2 years ago committed by Bogdan
parent 257d279e43
commit 10766dd227

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Books
Author FindByName(string cleanName); Author FindByName(string cleanName);
Author FindById(string foreignAuthorId); Author FindById(string foreignAuthorId);
Dictionary<int, string> AllAuthorPaths(); Dictionary<int, string> AllAuthorPaths();
Dictionary<int, List<int>> AllAuthorTags();
Author GetAuthorByMetadataId(int authorMetadataId); Author GetAuthorByMetadataId(int authorMetadataId);
List<Author> GetAuthorsByMetadataId(IEnumerable<int> authorMetadataId); List<Author> GetAuthorsByMetadataId(IEnumerable<int> authorMetadataId);
} }
@ -65,6 +66,15 @@ namespace NzbDrone.Core.Books
} }
} }
public Dictionary<int, List<int>> 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<KeyValuePair<int, List<int>>>(strSql).ToDictionary(x => x.Key, x => x.Value);
}
}
public Author GetAuthorByMetadataId(int authorMetadataId) public Author GetAuthorByMetadataId(int authorMetadataId)
{ {
return Query(s => s.AuthorMetadataId == authorMetadataId).SingleOrDefault(); return Query(s => s.AuthorMetadataId == authorMetadataId).SingleOrDefault();

@ -24,6 +24,7 @@ namespace NzbDrone.Core.Books
List<Author> GetReportCandidates(string reportTitle); List<Author> GetReportCandidates(string reportTitle);
void DeleteAuthor(int authorId, bool deleteFiles, bool addImportListExclusion = false); void DeleteAuthor(int authorId, bool deleteFiles, bool addImportListExclusion = false);
List<Author> GetAllAuthors(); List<Author> GetAllAuthors();
Dictionary<int, List<int>> GetAllAuthorTags();
List<Author> AllForTag(int tagId); List<Author> AllForTag(int tagId);
Author UpdateAuthor(Author author); Author UpdateAuthor(Author author);
List<Author> UpdateAuthors(List<Author> authors, bool useExistingRelativeFolder); List<Author> UpdateAuthors(List<Author> authors, bool useExistingRelativeFolder);
@ -185,6 +186,11 @@ namespace NzbDrone.Core.Books
return _cache.Get("GetAllAuthors", () => _authorRepository.All().ToList(), TimeSpan.FromSeconds(30)); return _cache.Get("GetAllAuthors", () => _authorRepository.All().ToList(), TimeSpan.FromSeconds(30));
} }
public Dictionary<int, List<int>> GetAllAuthorTags()
{
return _authorRepository.AllAuthorTags();
}
public Dictionary<int, string> AllAuthorPaths() public Dictionary<int, string> AllAuthorPaths()
{ {
return _authorRepository.AllAuthorPaths(); return _authorRepository.AllAuthorPaths();

@ -106,7 +106,7 @@ namespace NzbDrone.Core.Tags
var importLists = _importListFactory.All(); var importLists = _importListFactory.All();
var notifications = _notificationFactory.All(); var notifications = _notificationFactory.All();
var restrictions = _releaseProfileService.All(); var restrictions = _releaseProfileService.All();
var authors = _authorService.GetAllAuthors(); var authors = _authorService.GetAllAuthorTags();
var indexers = _indexerService.All(); var indexers = _indexerService.All();
var rootFolders = _rootFolderService.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(), 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(), 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(), 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(), 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() RootFolderIds = rootFolders.Where(c => c.DefaultTags.Contains(tag.Id)).Select(c => c.Id).ToList()
}); });

Loading…
Cancel
Save