Random Fixes (#3549)

Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
Joe Milazzo 2025-02-15 17:25:18 -06:00 committed by GitHub
parent ea81a2f432
commit 39726f8c4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 425 additions and 107 deletions

View file

@ -122,6 +122,7 @@ public class ReaderService : IReaderService
var seenVolume = new Dictionary<int, bool>();
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdAsync(seriesId);
if (series == null) throw new KavitaException("series-doesnt-exist");
foreach (var chapter in chapters)
{
var userProgress = GetUserProgressForChapter(user, chapter);
@ -135,10 +136,6 @@ public class ReaderService : IReaderService
SeriesId = seriesId,
ChapterId = chapter.Id,
LibraryId = series.LibraryId,
Created = DateTime.Now,
CreatedUtc = DateTime.UtcNow,
LastModified = DateTime.Now,
LastModifiedUtc = DateTime.UtcNow
});
}
else
@ -206,7 +203,7 @@ public class ReaderService : IReaderService
/// <param name="user">Must have Progresses populated</param>
/// <param name="chapter"></param>
/// <returns></returns>
private static AppUserProgress? GetUserProgressForChapter(AppUser user, Chapter chapter)
private AppUserProgress? GetUserProgressForChapter(AppUser user, Chapter chapter)
{
AppUserProgress? userProgress = null;
@ -226,11 +223,12 @@ public class ReaderService : IReaderService
var progresses = user.Progresses.Where(x => x.ChapterId == chapter.Id && x.AppUserId == user.Id).ToList();
if (progresses.Count > 1)
{
user.Progresses = new List<AppUserProgress>
{
user.Progresses.First()
};
var highestProgress = progresses.Max(x => x.PagesRead);
var firstProgress = progresses.OrderBy(p => p.LastModifiedUtc).First();
firstProgress.PagesRead = highestProgress;
user.Progresses = [firstProgress];
userProgress = user.Progresses.First();
_logger.LogInformation("Trying to save progress and multiple progress entries exist, deleting and rewriting with highest progress rate: {@Progress}", userProgress);
}
}
@ -274,10 +272,6 @@ public class ReaderService : IReaderService
ChapterId = progressDto.ChapterId,
LibraryId = progressDto.LibraryId,
BookScrollId = progressDto.BookScrollId,
Created = DateTime.Now,
CreatedUtc = DateTime.UtcNow,
LastModified = DateTime.Now,
LastModifiedUtc = DateTime.UtcNow
});
_unitOfWork.UserRepository.Update(userWithProgress);
}