Scan Issues (#470)

* Fixed an oversight where unique file extensions for KavitaStats wouldn't ignore case.

* Fixed an issue where series were getting removed then re-added due to bad logic when comparing if the series from disk matched the series in DB based on format.
This commit is contained in:
Joseph Milazzo 2021-08-10 19:05:16 -05:00 committed by GitHub
parent 7e36c56416
commit 9c57984bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 8 deletions

View File

@ -20,7 +20,7 @@ namespace API.Data
{
var fileExtensions = await _dbContext.MangaFile
.AsNoTracking()
.Select(x => x.FilePath)
.Select(x => x.FilePath.ToLower())
.Distinct()
.ToArrayAsync();

View File

@ -260,13 +260,43 @@ namespace API.Services.Tasks
public IEnumerable<Series> FindSeriesNotOnDisk(ICollection<Series> existingSeries, Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)
{
// It is safe to check only first since Parser ensures that a Series only has one type
var format = MangaFormat.Unknown;
var firstPs = parsedSeries.Keys.DistinctBy(ps => ps.Format).FirstOrDefault();
if (firstPs != null) format = firstPs.Format;
var foundSeries = parsedSeries.Select(s => s.Key.Name).ToList();
return existingSeries.Where(es => !es.NameInList(foundSeries) || es.Format != format);
return existingSeries.Where(es => !es.NameInList(foundSeries) && !SeriesHasMatchingParserInfoFormat(es, parsedSeries));
}
/// <summary>
/// Checks each parser info to see if there is a name match and if so, checks if the format matches the Series object.
/// This accounts for if the Series has an Unknown type and if so, considers it matching.
/// </summary>
/// <param name="series"></param>
/// <param name="parsedSeries"></param>
/// <returns></returns>
private static bool SeriesHasMatchingParserInfoFormat(Series series,
Dictionary<ParsedSeries, List<ParserInfo>> parsedSeries)
{
var format = MangaFormat.Unknown;
foreach (var pSeries in parsedSeries.Keys)
{
var name = pSeries.Name;
var normalizedName = Parser.Parser.Normalize(name);
if (normalizedName == series.NormalizedName ||
normalizedName == Parser.Parser.Normalize(series.Name) ||
name == series.Name || name == series.LocalizedName ||
name == series.OriginalName ||
normalizedName == Parser.Parser.Normalize(series.OriginalName))
{
format = pSeries.Format;
break;
}
}
if (series.Format == MangaFormat.Unknown && format != MangaFormat.Unknown)
{
return true;
}
return format == series.Format;
}
/// <summary>