Continue Reading Bugfix (#2010)

* Fixed an edge case where continue point wasn't considering any chapters that had progress.

Continue point is now slightly faster and uses less memory.

* Added a unit test for a user's case. Still not reproducible
This commit is contained in:
Joe Milazzo 2023-05-22 09:25:56 -05:00 committed by GitHub
parent 84d45a15d0
commit 7fcec4a112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 191 additions and 5 deletions

View file

@ -1986,6 +1986,184 @@ public class ReaderServiceTests
Assert.Equal(4, nextChapter.VolumeId);
}
/// <summary>
/// Volume 1-10 are fully read (single volumes),
/// Special 1 is fully read
/// Chapters 56-90 are read
/// Chapter 91 has partial progress on
/// </summary>
[Fact]
public async Task GetContinuePoint_ShouldReturnLastLooseChapter()
{
await ResetDb();
var series = new SeriesBuilder("Test")
.WithVolume(new VolumeBuilder("1")
.WithChapter(new ChapterBuilder("1").WithPages(1).Build())
.Build())
.WithVolume(new VolumeBuilder("2")
.WithChapter(new ChapterBuilder("21").WithPages(1).Build())
.WithChapter(new ChapterBuilder("22").WithPages(1).Build())
.Build())
.WithVolume(new VolumeBuilder("0")
.WithChapter(new ChapterBuilder("51").WithPages(1).Build())
.WithChapter(new ChapterBuilder("52").WithPages(1).Build())
.WithChapter(new ChapterBuilder("91").WithPages(2).Build())
.WithChapter(new ChapterBuilder("Special").WithIsSpecial(true).WithPages(1).Build())
.Build())
.Build();
series.Library = new LibraryBuilder("Test LIb", LibraryType.Manga).Build();
_context.Series.Add(series);
_context.AppUser.Add(new AppUser()
{
UserName = "majora2007"
});
await _context.SaveChangesAsync();
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 1,
SeriesId = 1,
VolumeId = 1
}, 1);
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 2,
SeriesId = 1,
VolumeId = 1
}, 1);
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 3,
SeriesId = 1,
VolumeId = 2
}, 1);
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 4,
SeriesId = 1,
VolumeId = 2
}, 1);
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 5,
SeriesId = 1,
VolumeId = 2
}, 1);
// Chapter 91 has partial progress, hence it should resume there
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 6,
SeriesId = 1,
VolumeId = 2
}, 1);
// Special is fully read
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 7,
SeriesId = 1,
VolumeId = 2
}, 1);
await _context.SaveChangesAsync();
var nextChapter = await _readerService.GetContinuePoint(1, 1);
Assert.Equal("91", nextChapter.Range);
}
[Fact]
public async Task GetContinuePoint_DuplicateIssueNumberBetweenChapters()
{
await ResetDb();
var series = new SeriesBuilder("Test")
.WithVolume(new VolumeBuilder("1")
.WithChapter(new ChapterBuilder("1").WithPages(1).Build())
.WithChapter(new ChapterBuilder("2").WithPages(1).Build())
.WithChapter(new ChapterBuilder("21").WithPages(1).Build())
.WithChapter(new ChapterBuilder("22").WithPages(1).Build())
.WithChapter(new ChapterBuilder("32").WithPages(1).Build())
.Build())
.WithVolume(new VolumeBuilder("2")
.WithChapter(new ChapterBuilder("1").WithPages(1).Build())
.WithChapter(new ChapterBuilder("2").WithPages(1).Build())
.WithChapter(new ChapterBuilder("21").WithPages(1).Build())
.WithChapter(new ChapterBuilder("22").WithPages(1).Build())
.WithChapter(new ChapterBuilder("32").WithPages(1).Build())
.Build())
.Build();
series.Library = new LibraryBuilder("Test LIb", LibraryType.Manga).Build();
_context.Series.Add(series);
_context.AppUser.Add(new AppUser()
{
UserName = "majora2007"
});
await _context.SaveChangesAsync();
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 1,
SeriesId = 1,
VolumeId = 1
}, 1);
await _context.SaveChangesAsync();
var nextChapter = await _readerService.GetContinuePoint(1, 1);
Assert.Equal("2", nextChapter.Range);
Assert.Equal(1, nextChapter.VolumeId);
// Mark chapter 2 as read
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 2,
SeriesId = 1,
VolumeId = 1
}, 1);
await _context.SaveChangesAsync();
nextChapter = await _readerService.GetContinuePoint(1, 1);
Assert.Equal("21", nextChapter.Range);
Assert.Equal(1, nextChapter.VolumeId);
// Mark chapter 21 as read
await _readerService.SaveReadingProgress(new ProgressDto()
{
PageNum = 1,
ChapterId = 3,
SeriesId = 1,
VolumeId = 1
}, 1);
await _context.SaveChangesAsync();
nextChapter = await _readerService.GetContinuePoint(1, 1);
Assert.Equal("22", nextChapter.Range);
Assert.Equal(1, nextChapter.VolumeId);
}
#endregion
#region MarkChaptersUntilAsRead