From ca5c666b7b8652b9756397f4cfe62a985e359f96 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Wed, 31 Mar 2021 14:50:03 -0500 Subject: [PATCH] In Progress Activity Stream Fixes (#136) * Fixed a bug in In-Progress where it wasn't properly fetching series. --- API/Data/SeriesRepository.cs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/API/Data/SeriesRepository.cs b/API/Data/SeriesRepository.cs index 84b904b51..b9bae9773 100644 --- a/API/Data/SeriesRepository.cs +++ b/API/Data/SeriesRepository.cs @@ -302,22 +302,27 @@ namespace API.Data /// public async Task> GetInProgress(int userId, int libraryId, int limit) { + + var seriesWithProgress = _context.Series + .Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new + { + Series = s, + PagesRead = _context.AppUserProgresses.Where(s1 => s1.SeriesId == s.Id).Sum(s1 => s1.PagesRead), + progress.AppUserId, + progress.LastModified + }) + .Where(s => s.AppUserId == userId + && s.PagesRead > 0 + && s.PagesRead < s.Series.Pages + && (libraryId <= 0 || s.Series.LibraryId == libraryId)) + .Select(s => s.Series.Id); + + var series = await _context.Series - .Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new - { - Series = s, - PagesRead = _context.AppUserProgresses.Where(s1 => s1.SeriesId == s.Id).Sum(s1 => s1.PagesRead), - progress.AppUserId, - progress.LastModified - }) - .Where(s => s.AppUserId == userId - && s.PagesRead > 0 - && s.PagesRead < s.Series.Pages - && (libraryId <= 0 || s.Series.LibraryId == libraryId) ) - .Take(limit) + .Where(s => seriesWithProgress.Contains(s.Id)) .OrderByDescending(s => s.LastModified) - .Select(s => s.Series) - .ProjectTo(_mapper.ConfigurationProvider) + .Take(limit) + .ProjectTo(_mapper.ConfigurationProvider) .AsNoTracking() .ToListAsync(); return series.DistinctBy(s => s.Name);