mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
ContinueReading has been pulled from UI. The query doesn't work and no longer sure I need.
This commit is contained in:
parent
a125b2ac0b
commit
f77de66d97
@ -18,6 +18,7 @@
|
||||
public int SeriesId { get; init; }
|
||||
public int LibraryId { get; init; }
|
||||
public string SeriesName { get; init; }
|
||||
public int VolumeId { get; init; }
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
var volumeQuery = _context.Volume
|
||||
.Join(_context.AppUserProgresses, v => v.Id, aup => aup.VolumeId, (volume, progress) => new
|
||||
{
|
||||
Chapter = chapter,
|
||||
Progress = progress
|
||||
volume,
|
||||
progress
|
||||
})
|
||||
.Join(_context.Series, arg => arg.Progress.SeriesId, series => series.Id, (arg, series) =>
|
||||
.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,
|
||||
chapter,
|
||||
progress
|
||||
})
|
||||
.Join(_context.Series, arg => arg.progress.SeriesId, s => s.Id, (arg, series) => new
|
||||
{
|
||||
Chapter = arg.chapter,
|
||||
Progress = arg.progress,
|
||||
Series = series
|
||||
})
|
||||
.AsNoTracking()
|
||||
.Where(arg => arg.Progress.AppUserId == userId
|
||||
&& arg.Progress.PagesRead < arg.Chapter.Pages)
|
||||
.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,
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user