From c16ca46f11db26138993c048f31695bd5c46e40d Mon Sep 17 00:00:00 2001 From: Qstick Date: Fri, 27 Nov 2020 00:36:18 -0500 Subject: [PATCH] Fixed: Tags View in UI Slow due to All() Movie Call --- src/NzbDrone.Core/Movies/MovieRepository.cs | 11 +++++++++++ src/NzbDrone.Core/Movies/MovieService.cs | 7 +++---- src/NzbDrone.Core/Tags/TagService.cs | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core/Movies/MovieRepository.cs b/src/NzbDrone.Core/Movies/MovieRepository.cs index b107ec5ca..8fe7c8f1f 100644 --- a/src/NzbDrone.Core/Movies/MovieRepository.cs +++ b/src/NzbDrone.Core/Movies/MovieRepository.cs @@ -29,6 +29,7 @@ namespace NzbDrone.Core.Movies Movie FindByPath(string path); List AllMoviePaths(); List AllMovieTmdbIds(); + Dictionary> AllMovieTags(); List GetRecommendations(); } @@ -290,6 +291,16 @@ namespace NzbDrone.Core.Movies } } + public Dictionary> AllMovieTags() + { + using (var conn = _database.OpenConnection()) + { + string strSql = "SELECT Id AS [Key], Tags AS [Value] FROM Movies"; + var tags = conn.Query>>(strSql).ToDictionary(x => x.Key, x => x.Value); + return tags; + } + } + public List GetRecommendations() { var recommendations = new List>(); diff --git a/src/NzbDrone.Core/Movies/MovieService.cs b/src/NzbDrone.Core/Movies/MovieService.cs index 3cec78c6b..e8e83e914 100644 --- a/src/NzbDrone.Core/Movies/MovieService.cs +++ b/src/NzbDrone.Core/Movies/MovieService.cs @@ -41,7 +41,7 @@ namespace NzbDrone.Core.Movies void DeleteMovie(int movieId, bool deleteFiles, bool addExclusion = false); void DeleteMovies(List movieIds, bool deleteFiles, bool addExclusion = false); List GetAllMovies(); - List AllForTag(int tagId); + Dictionary> AllMovieTags(); Movie UpdateMovie(Movie movie); List UpdateMovie(List movie, bool useExistingRelativeFolder); List FilterExistingMovies(List movies); @@ -227,10 +227,9 @@ namespace NzbDrone.Core.Movies return _movieRepository.All().ToList(); } - public List AllForTag(int tagId) + public Dictionary> AllMovieTags() { - return GetAllMovies().Where(s => s.Tags.Contains(tagId)) - .ToList(); + return _movieRepository.AllMovieTags(); } public Movie UpdateMovie(Movie movie) diff --git a/src/NzbDrone.Core/Tags/TagService.cs b/src/NzbDrone.Core/Tags/TagService.cs index 159f2df7a..a6569c87e 100644 --- a/src/NzbDrone.Core/Tags/TagService.cs +++ b/src/NzbDrone.Core/Tags/TagService.cs @@ -79,7 +79,7 @@ namespace NzbDrone.Core.Tags var importLists = _importListFactory.AllForTag(tagId); var notifications = _notificationFactory.AllForTag(tagId); var restrictions = _restrictionService.AllForTag(tagId); - var movies = _movieService.AllForTag(tagId); + var movies = _movieService.AllMovieTags().Where(x => x.Value.Contains(tagId)).Select(x => x.Key).ToList(); return new TagDetails { @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Tags ImportListIds = importLists.Select(c => c.Id).ToList(), NotificationIds = notifications.Select(c => c.Id).ToList(), RestrictionIds = restrictions.Select(c => c.Id).ToList(), - MovieIds = movies.Select(c => c.Id).ToList() + MovieIds = movies }; } @@ -100,7 +100,7 @@ namespace NzbDrone.Core.Tags var importLists = _importListFactory.All(); var notifications = _notificationFactory.All(); var restrictions = _restrictionService.All(); - var movies = _movieService.GetAllMovies(); + var movies = _movieService.AllMovieTags(); var details = new List(); @@ -114,7 +114,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(), - MovieIds = movies.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList() + MovieIds = movies.Where(c => c.Value.Contains(tag.Id)).Select(c => c.Key).ToList() }); }