Scanner Fixes (#3619)
Co-authored-by: Fesaa <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
parent
b4061e3711
commit
ab540c0ea6
8 changed files with 340 additions and 19 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -865,8 +865,11 @@ public class ProcessSeries : IProcessSeries
|
|||
var fileInfo = _directoryService.FileSystem.FileInfo.New(info.FullFilePath);
|
||||
if (existingFile != null)
|
||||
{
|
||||
// TODO: I wonder if we can simplify this force check.
|
||||
existingFile.Format = info.Format;
|
||||
|
||||
if (!forceUpdate && !_fileService.HasFileBeenModifiedSince(existingFile.FilePath, existingFile.LastModified) && existingFile.Pages != 0) return;
|
||||
|
||||
existingFile.Pages = _readingItemService.GetNumberOfPages(info.FullFilePath, info.Format);
|
||||
existingFile.Extension = fileInfo.Extension.ToLowerInvariant();
|
||||
existingFile.FileName = Parser.Parser.RemoveExtensionIfSupported(existingFile.FilePath);
|
||||
|
|
|
@ -335,11 +335,21 @@ public class ScannerService : IScannerService
|
|||
|
||||
private static Dictionary<ParsedSeries, IList<ParserInfo>> TrackFoundSeriesAndFiles(IList<ScannedSeriesResult> seenSeries)
|
||||
{
|
||||
// Why does this only grab things that have changed?
|
||||
var parsedSeries = new Dictionary<ParsedSeries, IList<ParserInfo>>();
|
||||
foreach (var series in seenSeries.Where(s => s.ParsedInfos.Count > 0 && s.HasChanged))
|
||||
foreach (var series in seenSeries.Where(s => s.ParsedInfos.Count > 0)) // && s.HasChanged
|
||||
{
|
||||
var parsedFiles = series.ParsedInfos;
|
||||
parsedSeries.Add(series.ParsedSeries, parsedFiles);
|
||||
series.ParsedSeries.HasChanged = series.HasChanged;
|
||||
|
||||
if (series.HasChanged)
|
||||
{
|
||||
parsedSeries.Add(series.ParsedSeries, parsedFiles);
|
||||
}
|
||||
else
|
||||
{
|
||||
parsedSeries.Add(series.ParsedSeries, []);
|
||||
}
|
||||
}
|
||||
|
||||
return parsedSeries;
|
||||
|
@ -601,6 +611,12 @@ public class ScannerService : IScannerService
|
|||
|
||||
foreach (var series in parsedSeries)
|
||||
{
|
||||
if (!series.Key.HasChanged)
|
||||
{
|
||||
_logger.LogDebug("{Series} hasn't changed", series.Key.Name);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Filter out ParserInfos where FullFilePath is empty (i.e., folder not modified)
|
||||
var validInfos = series.Value.Where(info => !string.IsNullOrEmpty(info.Filename)).ToList();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue