From 005ad00caf8cd6e439a53216f350877f02645b93 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 28 Nov 2021 16:38:45 -0600 Subject: [PATCH] Speed up History by Movie endpoint by avoiding multiple db calls Closes #6704 --- src/NzbDrone.Core/History/HistoryRepository.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/History/HistoryRepository.cs b/src/NzbDrone.Core/History/HistoryRepository.cs index bf7617260..cd83e5625 100644 --- a/src/NzbDrone.Core/History/HistoryRepository.cs +++ b/src/NzbDrone.Core/History/HistoryRepository.cs @@ -58,14 +58,17 @@ namespace NzbDrone.Core.History public List GetByMovieId(int movieId, MovieHistoryEventType? eventType) { - var query = Query(x => x.MovieId == movieId); + var builder = new SqlBuilder() + .Join((h, m) => h.MovieId == m.Id) + .Join((m, p) => m.ProfileId == p.Id) + .Where(h => h.MovieId == movieId); if (eventType.HasValue) { - query = query.Where(h => h.EventType == eventType).ToList(); + builder.Where(h => h.EventType == eventType); } - return query.OrderByDescending(h => h.Date).ToList(); + return PagedQuery(builder).OrderByDescending(h => h.Date).ToList(); } public void DeleteForMovies(List movieIds) @@ -94,14 +97,17 @@ namespace NzbDrone.Core.History public List Since(DateTime date, MovieHistoryEventType? eventType) { - var builder = Builder().Where(x => x.Date >= date); + var builder = new SqlBuilder() + .Join((h, m) => h.MovieId == m.Id) + .Join((m, p) => m.ProfileId == p.Id) + .Where(x => x.Date >= date); if (eventType.HasValue) { builder.Where(h => h.EventType == eventType); } - return Query(builder).OrderBy(h => h.Date).ToList(); + return PagedQuery(builder).OrderBy(h => h.Date).ToList(); } } }