Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

ContinueReading has been pulled from UI. The query doesn't work and no longer sure I need.

Joseph Milazzof77de66d970f
diff --git a/API/DTOs/InProgressChapterDto.cs b/API/DTOs/InProgressChapterDto.cs
index f0a0096ef..08bce3fc6 100644
--- a/API/DTOs/InProgressChapterDto.cs
+++ b/API/DTOs/InProgressChapterDto.cs
@@ -18,6 +18,7 @@
public int SeriesId { get; init; }
public int LibraryId { get; init; }
public string SeriesName { get; init; }
+ public int VolumeId { get; init; }
}
}
\ No newline at end of file
diff --git a/API/Data/SeriesRepository.cs b/API/Data/SeriesRepository.cs
index dbee172b9..52be7dac7 100644
--- a/API/Data/SeriesRepository.cs
+++ b/API/Data/SeriesRepository.cs
@@ -306,6 +306,7 @@ namespace API.Data
/// <returns></returns>
public async Task<IEnumerable<SeriesDto>> GetInProgress(int userId, int libraryId, int limit)
{
+ // TODO: Idea: Put Total PagesRead and as return so that we can show a progress bar for full series read progress
var series = await _context.Series
.Join(_context.AppUserProgresses, s => s.Id, progress => progress.SeriesId, (s, progress) => new
{
diff --git a/API/Data/VolumeRepository.cs b/API/Data/VolumeRepository.cs
index 35119efa8..f0e183805 100644
--- a/API/Data/VolumeRepository.cs
+++ b/API/Data/VolumeRepository.cs
@@ -100,42 +100,112 @@ namespace API.Data
/// <returns></returns>
public async Task<IEnumerable<InProgressChapterDto>> GetContinueReading(int userId, int libraryId, int limit)
{
+ /** TODO: Fix this SQL
+ * SELECT * FROM
+ (
+ SELECT * FROM Chapter C WHERE C.VolumeId IN (SELECT Id from Volume where SeriesId = 1912)
+ ) C INNER JOIN AppUserProgresses AUP ON AUP.ChapterId = C.Id
+ INNER JOIN Series S ON AUP.SeriesId = S.Id
+ WHERE AUP.AppUserId = 1 AND AUP.PagesRead < C.Pages
+ */
_logger.LogInformation("Get Continue Reading");
- var chapters = await _context.Chapter
- .Join(_context.AppUserProgresses, c => c.Id, p => p.ChapterId,
- (chapter, progress) =>
- new
- {
- Chapter = chapter,
- Progress = progress
- })
- .Join(_context.Series, arg => arg.Progress.SeriesId, series => series.Id, (arg, series) =>
+ var volumeQuery = _context.Volume
+ .Join(_context.AppUserProgresses, v => v.Id, aup => aup.VolumeId, (volume, progress) => new
+ {
+ volume,
+ progress
+ })
+ .Where(arg => arg.volume.SeriesId == arg.progress.SeriesId && arg.progress.AppUserId == userId)
+ .AsNoTracking()
+ .Select(arg => new
+ {
+ VolumeId = arg.volume.Id,
+ VolumeNumber = arg.volume.Number
+ }); // I think doing a join on this would be better
+
+ var volumeIds = (await volumeQuery.ToListAsync()).Select(s => s.VolumeId);
+
+ var chapters2 = await _context.Chapter.Where(c => volumeIds.Contains(c.VolumeId))
+ .Join(_context.AppUserProgresses, chapter => chapter.Id, aup => aup.ChapterId, (chapter, progress) =>
new
{
- arg.Chapter,
- arg.Progress,
- Series = series
+ chapter,
+ progress
})
- .AsNoTracking()
- .Where(arg => arg.Progress.AppUserId == userId
- && arg.Progress.PagesRead < arg.Chapter.Pages)
+ .Join(_context.Series, arg => arg.progress.SeriesId, s => s.Id, (arg, series) => new
+ {
+ Chapter = arg.chapter,
+ Progress = arg.progress,
+ Series = series
+ })
+ .Where(o => o.Progress.AppUserId == userId && o.Progress.PagesRead < o.Series.Pages)
+ .Select(arg => new
+ {
+ Chapter = arg.Chapter,
+ Progress = arg.Progress,
+ SeriesId = arg.Series.Id,
+ SeriesName = arg.Series.Name,
+ LibraryId = arg.Series.LibraryId,
+ TotalPages = arg.Series.Pages
+ })
.OrderByDescending(d => d.Progress.LastModified)
.Take(limit)
.ToListAsync();
- return chapters
+ return chapters2
.OrderBy(c => float.Parse(c.Chapter.Number), new ChapterSortComparer())
- .DistinctBy(p => p.Series.Id)
+ .DistinctBy(p => p.SeriesId)
.Select(arg => new InProgressChapterDto()
{
Id = arg.Chapter.Id,
Number = arg.Chapter.Number,
Range = arg.Chapter.Range,
SeriesId = arg.Progress.SeriesId,
- SeriesName = arg.Series.Name,
- LibraryId = arg.Series.LibraryId,
+ SeriesName = arg.SeriesName,
+ LibraryId = arg.LibraryId,
Pages = arg.Chapter.Pages,
+ VolumeId = arg.Chapter.VolumeId
});
+
+
+
+ // var chapters = await _context.Chapter
+ // .Join(_context.AppUserProgresses, c => c.Id, p => p.ChapterId,
+ // (chapter, progress) =>
+ // new
+ // {
+ // Chapter = chapter,
+ // Progress = progress
+ // })
+ // .Join(_context.Series, arg => arg.Progress.SeriesId, series => series.Id, (arg, series) =>
+ // new
+ // {
+ // arg.Chapter,
+ // arg.Progress,
+ // Series = series,
+ // VolumeIds = _context.Volume.Where(v => v.SeriesId == series.Id).Select(s => s.Id).ToList()
+ // })
+ // .AsNoTracking()
+ // .Where(arg => arg.Progress.AppUserId == userId
+ // && arg.Progress.PagesRead < arg.Chapter.Pages
+ // && arg.VolumeIds.Contains(arg.Progress.VolumeId))
+ // .OrderByDescending(d => d.Progress.LastModified)
+ // .Take(limit)
+ // .ToListAsync();
+
+ // return chapters
+ // .OrderBy(c => float.Parse(c.Chapter.Number), new ChapterSortComparer())
+ // .DistinctBy(p => p.Series.Id)
+ // .Select(arg => new InProgressChapterDto()
+ // {
+ // Id = arg.Chapter.Id,
+ // Number = arg.Chapter.Number,
+ // Range = arg.Chapter.Range,
+ // SeriesId = arg.Progress.SeriesId,
+ // SeriesName = arg.Series.Name,
+ // LibraryId = arg.Series.LibraryId,
+ // Pages = arg.Chapter.Pages,
+ // });
}
}
}
\ No newline at end of file