Scanner Fixes (#3619)

Co-authored-by: Fesaa <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
Joe Milazzo 2025-03-12 17:25:15 -05:00 committed by GitHub
parent b4061e3711
commit ab540c0ea6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 340 additions and 19 deletions

View file

@ -32,6 +32,10 @@ public class ParsedSeries
/// Format of the Series
/// </summary>
public required MangaFormat Format { get; init; }
/// <summary>
/// Has this Series changed or not aka do we need to process it or not.
/// </summary>
public bool HasChanged { get; set; }
}
public class ScanResult
@ -178,7 +182,7 @@ public class ParseScannedFiles
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.FileScanProgressEvent(directory, library.Name, ProgressEventType.Updated));
if (HasSeriesFolderNotChangedSinceLastScan(seriesPaths, directory, forceCheck))
if (HasSeriesFolderNotChangedSinceLastScan(library, seriesPaths, directory, forceCheck))
{
HandleUnchangedFolder(result, folderPath, directory);
}
@ -196,15 +200,21 @@ public class ParseScannedFiles
/// <summary>
/// Checks against all folder paths on file if the last scanned is >= the directory's last write time, down to the second
/// </summary>
/// <param name="library"></param>
/// <param name="seriesPaths"></param>
/// <param name="directory">This should be normalized</param>
/// <param name="forceCheck"></param>
/// <returns></returns>
private bool HasSeriesFolderNotChangedSinceLastScan(IDictionary<string, IList<SeriesModified>> seriesPaths, string directory, bool forceCheck)
private bool HasSeriesFolderNotChangedSinceLastScan(Library library, IDictionary<string, IList<SeriesModified>> seriesPaths, string directory, bool forceCheck)
{
// With the bottom-up approach, this can report a false positive where a nested folder will get scanned even though a parent is the series
// This can't really be avoided. This is more likely to happen on Image chapter folder library layouts.
if (forceCheck || !seriesPaths.TryGetValue(directory, out var seriesList))
if (forceCheck)
{
return false;
}
// TryGetSeriesList falls back to parent folders to match to seriesList
var seriesList = TryGetSeriesList(library, seriesPaths, directory);
if (seriesList == null)
{
return false;
}
@ -222,6 +232,31 @@ public class ParseScannedFiles
return true;
}
private IList<SeriesModified>? TryGetSeriesList(Library library, IDictionary<string, IList<SeriesModified>> seriesPaths, string directory)
{
if (seriesPaths.Count == 0)
{
return null;
}
if (string.IsNullOrEmpty(directory))
{
return null;
}
if (library.Folders.Any(fp => fp.Path.Equals(directory)))
{
return null;
}
if (seriesPaths.TryGetValue(directory, out var seriesList))
{
return seriesList;
}
return TryGetSeriesList(library, seriesPaths, _directoryService.GetParentDirectoryName(directory));
}
/// <summary>
/// Handles directories that haven't changed since the last scan.
/// </summary>
@ -280,7 +315,7 @@ public class ParseScannedFiles
await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
MessageFactory.FileScanProgressEvent(normalizedPath, library.Name, ProgressEventType.Updated));
if (HasSeriesFolderNotChangedSinceLastScan(seriesPaths, normalizedPath, forceCheck))
if (HasSeriesFolderNotChangedSinceLastScan(library, seriesPaths, normalizedPath, forceCheck))
{
result.Add(CreateScanResult(folderPath, libraryRoot, false, ArraySegment<string>.Empty));
}
@ -721,7 +756,8 @@ public class ParseScannedFiles
// If folder hasn't changed, generate fake ParserInfos
if (!result.HasChanged)
{
result.ParserInfos = seriesPaths[normalizedFolder]
// We are certain TryGetSeriesList will return a valid result here, if the series wasn't present yet. It will have been changed.
result.ParserInfos = TryGetSeriesList(library, seriesPaths, normalizedFolder)!
.Select(fp => new ParserInfo { Series = fp.SeriesName, Format = fp.Format })
.ToList();