In Progress Activity Stream Fixes (#136)

* Fixed a bug in In-Progress where it wasn't properly fetching series.
This commit is contained in:
Joseph Milazzo 2021-03-31 14:50:03 -05:00 committed by GitHub
parent 667d1d2a4d
commit ca5c666b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -302,22 +302,27 @@ namespace API.Data
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<SeriesDto>> GetInProgress(int userId, int libraryId, int limit) public async Task<IEnumerable<SeriesDto>> 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 var series = await _context.Series
.Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new .Where(s => seriesWithProgress.Contains(s.Id))
{
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)
.OrderByDescending(s => s.LastModified) .OrderByDescending(s => s.LastModified)
.Select(s => s.Series) .Take(limit)
.ProjectTo<SeriesDto>(_mapper.ConfigurationProvider) .ProjectTo<SeriesDto>(_mapper.ConfigurationProvider)
.AsNoTracking() .AsNoTracking()
.ToListAsync(); .ToListAsync();
return series.DistinctBy(s => s.Name); return series.DistinctBy(s => s.Name);