Release Testing Day 2 (#1937)

* Removed unneded ngModel on password field

* Fixed some bad validation messages on Edit Reading List modal and disabled save button

* Added a lot of trace code to help debug a foreign constraint issue.

* Fixed a bug where after a series is scanned, generate covers for series didn't respect webp cover generation.

* Fixed library last scan being stored in Utc, but expected to be server time.

* Fixed up some of that trace logging being way too verbose. Fixed a case where when a missing storyarc number, the whole pair was dropped. Now, it will default that item to the end of the reading list.

Fixed a bug where Start and End dates weren't being calculated after generating a reading list.

* Fixed a bug where the default admin user for reading list creation from files was selecting the wrong user.

Changed so that when there is a bad pair (aka number missing) and only 1 pair, then we wont constantly reorder the item.

* Fixed unit test
This commit is contained in:
Joe Milazzo 2023-04-22 13:04:09 -05:00 committed by GitHub
parent 66f84a0ee3
commit c70154f428
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 163 additions and 51 deletions

View file

@ -13,9 +13,11 @@ using API.Entities;
using API.Entities.Enums;
using API.Helpers;
using API.Helpers.Builders;
using API.Services.Tasks.Scanner.Parser;
using API.SignalR;
using Kavita.Common;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
namespace API.Services;
@ -447,7 +449,7 @@ public class ReadingListService : IReadingListService
series.Metadata ??= new SeriesMetadataBuilder().Build();
foreach (var chapter in series.Volumes.SelectMany(v => v.Chapters))
{
List<Tuple<string, string>> pairs = new List<Tuple<string, string>>();
var pairs = new List<Tuple<string, string>>();
if (!string.IsNullOrEmpty(chapter.StoryArc))
{
pairs.AddRange(GeneratePairs(chapter.Files.FirstOrDefault()!.FilePath, chapter.StoryArc, chapter.StoryArcNumber));
@ -459,7 +461,6 @@ public class ReadingListService : IReadingListService
foreach (var arcPair in pairs)
{
var order = int.Parse(arcPair.Item2);
var readingList = await _unitOfWork.ReadingListRepository.GetReadingListByTitleAsync(arcPair.Item1, user.Id);
if (readingList == null)
{
@ -471,19 +472,36 @@ public class ReadingListService : IReadingListService
}
var items = readingList.Items.ToList();
var readingListItem = items.FirstOrDefault(item => item.Order == order);
var order = int.Parse(arcPair.Item2);
var readingListItem = items.FirstOrDefault(item => item.Order == order || item.ChapterId == chapter.Id);
if (readingListItem == null)
{
// If no number was provided in the reading list, we default to MaxValue and hence we should insert the item at the end of the list
if (order == int.MaxValue)
{
order = items.Count > 0 ? items.Max(item => item.Order) + 1 : 0;
}
items.Add(new ReadingListItemBuilder(order, series.Id, chapter.VolumeId, chapter.Id).Build());
}
else
{
ReorderItems(items, readingListItem.Id, order);
if (order == int.MaxValue)
{
_logger.LogWarning("{Filename} has a missing StoryArcNumber/AlternativeNumber but list already exists with this item. Skipping item", chapter.Files.FirstOrDefault()?.FilePath);
}
else
{
ReorderItems(items, readingListItem.Id, order);
}
}
readingList.Items = items;
await CalculateReadingListAgeRating(readingList);
await _unitOfWork.CommitAsync();
await CalculateStartAndEndDates(readingList);
if (_unitOfWork.HasChanges())
{
await _unitOfWork.CommitAsync();
}
}
}
}
@ -495,14 +513,19 @@ public class ReadingListService : IReadingListService
var arcs = storyArc.Split(",");
var arcNumbers = storyArcNumbers.Split(",");
if (arcNumbers.Length != arcs.Length)
if (arcNumbers.Count(s => !string.IsNullOrEmpty(s)) != arcs.Length)
{
_logger.LogError("There is a mismatch on StoryArc and StoryArcNumber for {FileName}", filename);
_logger.LogWarning("There is a mismatch on StoryArc and StoryArcNumber for {FileName}. Def", filename);
}
var maxPairs = Math.Min(arcs.Length, arcNumbers.Length);
for (var i = 0; i < maxPairs; i++)
{
// When there is a mismatch on arcs and arc numbers, then we should default to a high number
if (string.IsNullOrEmpty(arcNumbers[i]) && !string.IsNullOrEmpty(arcs[i]))
{
arcNumbers[i] = int.MaxValue.ToString();
}
if (string.IsNullOrEmpty(arcs[i]) || !int.TryParse(arcNumbers[i], out _)) continue;
data.Add(new Tuple<string, string>(arcs[i], arcNumbers[i]));
}