Further changes around ScanLibrary. Refactored DirectoryService search pattern to allow for greater re-usability. Fixed a bug where leftover chapters and volumes wouldn't get cleaned up when removed from disk.
This commit is contained in:
parent
d8d01ffaf6
commit
5c913ba615
7 changed files with 1967 additions and 42 deletions
|
@ -91,7 +91,7 @@ namespace API.Services
|
|||
/// <param name="root">Directory to scan</param>
|
||||
/// <param name="action">Action to apply on file path</param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public static int TraverseTreeParallelForEach(string root, Action<string> action)
|
||||
public static int TraverseTreeParallelForEach(string root, Action<string> action, string searchPattern)
|
||||
{
|
||||
//Count of files traversed and timer for diagnostic output
|
||||
var fileCount = 0;
|
||||
|
@ -130,7 +130,7 @@ namespace API.Services
|
|||
// TODO: In future, we need to take LibraryType into consideration for what extensions to allow (RAW should allow images)
|
||||
// or we need to move this filtering to another area (Process)
|
||||
// or we can get all files and put a check in place during Process to abandon files
|
||||
files = GetFilesWithCertainExtensions(currentDir, Parser.Parser.MangaFileExtensions)
|
||||
files = GetFilesWithCertainExtensions(currentDir, searchPattern)
|
||||
.ToArray();
|
||||
}
|
||||
catch (UnauthorizedAccessException e) {
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace API.Services
|
|||
_scannedSeries = null;
|
||||
}
|
||||
|
||||
[DisableConcurrentExecution(timeoutInSeconds: 120)]
|
||||
[DisableConcurrentExecution(timeoutInSeconds: 360)]
|
||||
public void ScanLibrary(int libraryId, bool forceUpdate)
|
||||
{
|
||||
_forceUpdate = forceUpdate;
|
||||
|
@ -105,7 +105,7 @@ namespace API.Services
|
|||
{
|
||||
_logger.LogError(exception, $"The file {f} could not be found");
|
||||
}
|
||||
});
|
||||
}, Parser.Parser.MangaFileExtensions);
|
||||
}
|
||||
catch (ArgumentException ex) {
|
||||
_logger.LogError(ex, $"The directory '{folderPath.Path}' does not exist");
|
||||
|
@ -170,17 +170,18 @@ namespace API.Services
|
|||
{
|
||||
try
|
||||
{
|
||||
// TODO: I don't need library here. It will always pull from allSeries
|
||||
var mangaSeries = ExistingOrDefault(library, allSeries, seriesKey) ?? new Series
|
||||
{
|
||||
Name = seriesKey, // NOTE: Should I apply Title casing here
|
||||
Name = seriesKey,
|
||||
OriginalName = seriesKey,
|
||||
NormalizedName = Parser.Parser.Normalize(seriesKey),
|
||||
SortName = seriesKey,
|
||||
Summary = ""
|
||||
};
|
||||
mangaSeries.NormalizedName = Parser.Parser.Normalize(mangaSeries.Name);
|
||||
|
||||
|
||||
|
||||
|
||||
UpdateSeries(ref mangaSeries, parsedSeries[seriesKey].ToArray());
|
||||
if (library.Series.Any(s => Parser.Parser.Normalize(s.Name) == mangaSeries.NormalizedName)) continue;
|
||||
_logger.LogInformation($"Added series {mangaSeries.Name}");
|
||||
|
@ -215,6 +216,20 @@ namespace API.Services
|
|||
}
|
||||
_logger.LogInformation($"Removed {count} series that are no longer on disk");
|
||||
}
|
||||
|
||||
private void RemoveVolumesNotOnDisk(Series series)
|
||||
{
|
||||
var volumes = series.Volumes.ToList();
|
||||
foreach (var volume in volumes)
|
||||
{
|
||||
var chapters = volume.Chapters;
|
||||
if (!chapters.Any())
|
||||
{
|
||||
series.Volumes.Remove(volume);
|
||||
//chapters.Select(c => c.Files).Any()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -260,9 +275,11 @@ namespace API.Services
|
|||
{
|
||||
_logger.LogInformation($"Updating entries for {series.Name}. {infos.Length} related files.");
|
||||
|
||||
UpdateVolumes(series, infos);
|
||||
series.Pages = series.Volumes.Sum(v => v.Pages);
|
||||
|
||||
UpdateVolumes(series, infos);
|
||||
RemoveVolumesNotOnDisk(series);
|
||||
series.Pages = series.Volumes.Sum(v => v.Pages);
|
||||
|
||||
_metadataService.UpdateMetadata(series, _forceUpdate);
|
||||
_logger.LogDebug($"Created {series.Volumes.Count} volumes on {series.Name}");
|
||||
}
|
||||
|
@ -352,10 +369,11 @@ namespace API.Services
|
|||
}
|
||||
|
||||
|
||||
private void UpdateVolumes(Series series, ParserInfo[] infos)
|
||||
private void UpdateVolumes(Series series, IReadOnlyCollection<ParserInfo> infos)
|
||||
{
|
||||
// BUG: If a volume no longer exists, it is not getting deleted.
|
||||
series.Volumes ??= new List<Volume>();
|
||||
_logger.LogDebug($"Updating Volumes for {series.Name}. {infos.Length} related files.");
|
||||
_logger.LogDebug($"Updating Volumes for {series.Name}. {infos.Count} related files.");
|
||||
var existingVolumes = _unitOfWork.SeriesRepository.GetVolumes(series.Id).ToList();
|
||||
|
||||
foreach (var info in infos)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue